Search code examples
node.jsamazon-web-servicesserverless

busboy Unexpected end of multipart data


i am new to nodejs and writing a api to upload the file to s3 but getting Error: Unexpected end of multipart data

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);
};

OUTPUT:

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)

Solution

  • this is happening on windows machine. after trying it on linux machine error is gone but cannot view the image