question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Busboy often throws Unhandled 'error' event Unexpected end of multipart data

See original GitHub issue

Hi everyone

I am using node v6.10.3 and Busboy 0.2.14. I use busboy to stream jpg image to a node server. But the issue is sometimes it works and some times it fails with the folowing error and crashes my server.

events.js:183 066466+00:00 app[web.1]: throw er; // Unhandled 'error' event 2018-06-19T00:45:07.066468+00:00 app[web.1]: ^ 2018-06-19T00:45:07.066470+00:00 app[web.1]: 066472+00:00 app[web.1]: Error: Unexpected end of multipart data 2018-06-19T00:45:07.066474+00:00 app[web.1]: at /app/node_modules/busboy/node_modules/dicer/lib/Dicer.js:62:28

Here is my code to handle the file

 req.busboy.on('file', function (fieldname, file, filename) {
   console.log("Uploading: " + (filename)); 
   fstream = fs.createWriteStream(__dirname + '/public/img/'+ filename);

   file.on('data', function(chunk) {
     fstream.write(chunk);
   });

   file.on('end', function() {
     fstream.end();
     console.log('File [' + fieldname + '] Finished sucessfully');
    });
  file.on('error',function(err){
    console.log('fstream error' + err);
    file.unpipe();
  });
});

I have tried to follow similar issues online, but no success. Can somebody please help me what could be the issue here? Thank you in advance.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
0xCAFEADD1C7commented, Sep 9, 2019

@trunderman If you still need the answer, you must add an error handler to the file objected got from busboy. You’ll have something like :

busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
  // with this handler, it won't throw at a higher level
  file.on('error', function(err) {
    // do whatever you want with your error
  })
});

Note that the error event will also be emitted on the busboy object (so busboy.on('error', () => { ... }) will also get an event)

1reaction
trundermancommented, Jul 10, 2019

@david1921 how did you go about handling the error correctly?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error "Unexpected end of multipart data" in busboy file upload
For me, I received this error when I used \n newlines instead of \r\n newlines when formatting my post body on the client...
Read more >
Error "Unexpected End Of Multipart Data" In Busboy ... - ADocLib
I use busboy to stream jpg image to a node server.Busboy often throws Unhandled 'error' event Unexpected end of multipart data #171.
Read more >
Error “Unexpected end of multipart data” in busboy file upload
The problem is sometimes it works(file get uploaded succsesfully) and sometimes i get error Unexpected end of multipart data and the application crash....
Read more >
Error: Unexpected end of multipart data - Busboy and Dicer
I'm trying to use an endpoint node to upload a file to s3 by form-data. I'm using multer, multer-s3 and express.
Read more >
busboy/multipart.js at master - GitHub - SegmentFault
A streaming parser for HTML form data for node.js. ... before busboy's 'finish' event is emitted ... throw new Error('Multipart: Boundary not found');....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found