#node.js #amazon-web-services #serverless
Вопрос:
я новичок в 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_pathdicerlibDicer.js:61:28
at processTicksAndRejections (internal/process/task_queues.js:77:11)
Ответ №1:
это происходит на компьютере с Windows. после попытки на компьютере с Linux ошибка исчезла, но изображение не просматривается