多部分数据意外结束
busboy Unexpected end of multipart data
我是 nodejs 的新手,正在编写 api 将文件上传到 s3 但出现错误:分段数据意外结束
var uploadImage = async (req, res) => {
var busboy = new Busboy({ headers: req.headers });
busboy.on('file', function (fieldname, file, filename, encoding, mimetype) {
console.log('File [' + fieldname + ']: filename: ' + filename + ', encoding: ' + encoding + ', mimetype: ' + mimetype);
file.on('data', function (data) {
console.log('File [' + fieldname + '] got ' + data.length + ' bytes');
});
file.on('end', function () {
console.log('File [' + fieldname + '] Finished');
});
});
busboy.on('field', function (fieldname, val, fieldnameTruncated, valTruncated, encoding, mimetype) {
console.log('Field [' + fieldname + ']: value: ' + inspect(val));
});
busboy.on('finish', function () {
console.log('Done parsing form!');
res.writeHead(303, { Connection: 'close', Location: '/' });
res.end();
});
req.pipe(busboy);
};
输出:
Serverless: POST /uploadImage (λ: API)
File [file]: filename: abcd.jpg, encoding: 7bit, mimetype: image/jpeg
File [file] got 58639 bytes
File [file] got 65536 bytes
File [file] got 65536 bytes
File [file] got 65536 bytes
File [file] got 65536 bytes
File [file] got 3253 bytes
Error --------------------------------------------------
Error: Unexpected end of multipart data
at some_path\dicer\lib\Dicer.js:61:28
at processTicksAndRejections (internal/process/task_queues.js:77:11)
这发生在 windows 机器上。在 linux 机器上尝试后错误消失但无法查看图像
我是 nodejs 的新手,正在编写 api 将文件上传到 s3 但出现错误:分段数据意外结束
var uploadImage = async (req, res) => {
var busboy = new Busboy({ headers: req.headers });
busboy.on('file', function (fieldname, file, filename, encoding, mimetype) {
console.log('File [' + fieldname + ']: filename: ' + filename + ', encoding: ' + encoding + ', mimetype: ' + mimetype);
file.on('data', function (data) {
console.log('File [' + fieldname + '] got ' + data.length + ' bytes');
});
file.on('end', function () {
console.log('File [' + fieldname + '] Finished');
});
});
busboy.on('field', function (fieldname, val, fieldnameTruncated, valTruncated, encoding, mimetype) {
console.log('Field [' + fieldname + ']: value: ' + inspect(val));
});
busboy.on('finish', function () {
console.log('Done parsing form!');
res.writeHead(303, { Connection: 'close', Location: '/' });
res.end();
});
req.pipe(busboy);
};
输出:
Serverless: POST /uploadImage (λ: API)
File [file]: filename: abcd.jpg, encoding: 7bit, mimetype: image/jpeg
File [file] got 58639 bytes
File [file] got 65536 bytes
File [file] got 65536 bytes
File [file] got 65536 bytes
File [file] got 65536 bytes
File [file] got 3253 bytes
Error --------------------------------------------------
Error: Unexpected end of multipart data
at some_path\dicer\lib\Dicer.js:61:28
at processTicksAndRejections (internal/process/task_queues.js:77:11)
这发生在 windows 机器上。在 linux 机器上尝试后错误消失但无法查看图像