In Next Js, I have a upload image endpoint.
const busboy = require('busboy')
export default function handle(req, res)
{
const bb = busboy({headers: req.headers});
bb.on('file', (fieldname, file, filename, encoding, mimetype) =>
{
res.status(200).send({ message: 'file' }); //doesn't do this
});
bb.on('close', () =>
{
res.status(201).send({ message: 'close' });
});
bb.on("finish", () =>
{
res.status(202).send({ message: 'finish' });
});
req.pipe(bb);
res.status(203).send({ message: 'failed' });
}
I'm trying to parse form data but busboy dosen't seem to enter on file, close, or finish. It skips them and returns the 203 failed message.
This is my next onsubmit event which calls this enpoint
function onFileUpload(e)
{
e.preventDefault();
let form = new FormData();
form.append("image", file, file.name);
console.log(form)
axios({
method: "post",
url: "http://localhost:3000/api/uploadImage",
data: form,
headers: form.getHeaders
//{'Content-Type': 'multipart/form-data'}
})
.then((res) =>
{
console.log(res);
});
}
Does anyone know what the issue is?