Error "Unexpected end of multipart data" in busboy file upload

I am using connect-busboy to upload a file to node / express app. The problem is that sometimes it works (the file uploads successfully) and sometimes I get an error Unexpected end of multipart data

and the application crashes. What could be causing this error? Any help on how to debug this would also be appreciated. I am using node version 5

and connect-busboy": "0.2.14"

Thanks in advance

router.route('/images')    
  .post (function(req, res) {

  var fstream;
  req.busboy.on('file', function (fieldname, file, filename) {

    fstream = fs.createWriteStream(__dirname + '/public/img/'+ filename);
    file.pipe(fstream);
    file.on('end', function() {
      console.log('File [' + fieldname + '] Finished sucessfully');
     });
    fstream.on('error',function(err){
      console.log('fstream error' + err);
      file.unpipe();
    });
    fstream.on('close', function () {
      res.status(200);
      res.json({ message: 'File uploaded' });

    });
  });
  req.pipe(req.busboy);

});

      

This is the error I am getting

throw er; // Unhandled 'error' event
: Error: Unexpected end of multipart data
2017-05-07T20:28:27.599826+00:00 app[web.1]:     at 
/app/node_modules/busboy/node_modules/dicer/lib/Dicer.js:62:28

      

+6


source to share


2 answers


For me, I got this error when I used \n

newlines instead \r\n

of newlines when formatting the message body on the client side.

When I fixed the line feeds (as seen in the code below) it worked.



fetch('/api/upload', 
  { method: 'POST',
    credentials: 'include',
    headers: {'Content-type': 'multipart/form-data; boundary=XXX' },
    body: '--XXX\r\nContent-Disposition: form-data; name="file"; filename="filename.csv"\r\nContent-Type: text/csv\r\n\r\nA,B,C\r\n1,1.1,name1\r\n2,2.2,name2\r\n\r\n--XXX--'
  });

      

0


source


This is a bug related to Firebase tools. I ran into this problem with the busboy package today and it cost me 2 hours to fix the problem. We just need to update our Firebase tools to fix this issue.

Case 1: If you have installed Firebase tools depending on package then run below code

npm i firebase-tools

      

Case 2: If you have installed Firebase tools as a global dependency, run below code



npm i -g firebase-tools

      

Working version of Firebase tools:

enter image description here

Hope this helps, check this link for more info .

0


source







All Articles