I am trying to recieve an image via busboy in Node.js post call however I am getting the following error:
Error: Unexpected end of multipart data
thrown by
..\node_modules\dicer\lib\Dicer.js:61:28
This is my code:
busboy.on('file', (fieldname, file, filename, encoding, mimetype) => {
console.log('ok', fieldname, file, filename, encoding, mimetype);
if (mimetype !== 'image/jpeg' && mimetype !== 'image/png') {
return res.status(400).json({ error: 'Wrong file type submitted' });
}
// my.image.png => ['my', 'image', 'png']
const imageExtension = filename.split('.')[filename.split('.').length - 1];
// 32756238461724837.png
imageFileName = `${Math.round(
Math.random() * 1000000000000
).toString()}.${imageExtension}`;
const filepath = path.join(os.tmpdir(), imageFileName);
imageToBeUploaded = { filepath, mimetype };
file.pipe(fs.createWriteStream(filepath));
});
I hope you can enlighten me on why this error is occuring as I am new to node.js