所以,我有这个帖子请求,它曾经工作正常,但是一旦我升级到 Node 10,我似乎无法弄清楚为什么文件事件完全停止触发......
router.post('/uploadImage', authenticate.FBAuth, (req, res) => {
const busboy = new BusBoy({ headers: req.headers });
let imageFileName;
let imageToBeUploaded = {};
busboy.on('file', function onFile(fieldname, file, filename, encoding, mimetype) {
console.log('onFile started');
if (mimetype !== 'image/png' && mimetype !== 'image/jpeg') {
return res.status(400).json({ error: 'Unsupported file format' });
}
const imageExtension = path.extname(filename);
imageFileName = `${Math.round(Math.random() * 100000000000)}.${imageExtension}`;
console.log(imageFileName);
const filepath = path.join(os.tmpdir(), imageFileName);
console.log(filepath);
imageToBeUploaded = { filepath, mimetype };
console.log(imageToBeUploaded);
file.pipe(fs.createWriteStream(filepath));
});
busboy.on('finish', function onFinish() {
admin …Run Code Online (Sandbox Code Playgroud)