Trying to send a blob object to my node server. On the client side I'm recording some audio using MediaRecorder and then I want to send the file to my server for processing.
saveButton.onclick = function(e, audio) {
var blobData = localStorage.getItem('recording');
console.log(blobData);
var fd = new FormData();
fd.append('upl', blobData, 'blobby.raw');
fetch('/api/test',
{
method: 'post',
body: fd
})
.then(function(response) {
console.log('done');
return response;
})
.catch(function(err){
console.log(err);
});
}
This is my express route, which uses multer:
var upload = multer({ dest: __dirname + '/../public/uploads/' });
var type = upload.single('upl');
app.post('/api/test', type, function (req, res) {
console.log(req.body);
console.log(req.file);
// do stuff with file
});
But my logs return nothing:
{ upl: '' }
undefined
Been spending a long time on this so any help appreciated!
var upload = multer({ dest: __dirname + '/../public/uploads/' }); var type = upload.single('upl');blobData, and what does theconsole.log(blobData)tell you.Content-Typeheader does the browser send if you view the fetch network request from your browser's web dev tools?{ upl: '' }Blob {size: 6937, type: "audio/wav"} size : 6937 type : "audio/wav" __proto__ : Blob