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.

File upload sometimes hangs - multer, busboy, or something else?

See original GitHub issue

HI!

I encountered some strange problem while using multer - sometimes it hangs while uploading the file.

When I am testing this behavior on my Ubuntu it succeeds every time, but when I switch to development server it hangs quite often.

I compared the behavior on both environments and added some basic printouts for troubleshooting:

app.use(multer({
  dest: './uploads/',
  rename: function (fieldname, filename) {
    return filename.replace(/\W+/g, '-').toLowerCase();
  },
  onFileUploadStart: function (file) {
    process.stderr.write('Uploading file..........');
  },
  onFileUploadComplete: function (file) {
    process.stderr.write('done\n');
  },

...

}));

On development server Uploading file......... is printed in the console but done doesn’t show up - which suggests it can be multer or busboy issue.

Full code in which I am using multer can be found here: https://github.com/aplikacjespoleczne/WizualizacjaBudzetu

Also for troubleshooting I’ve added the simmilar logging to the multer code (in index.js) :

        fileStream.on('data', function(data) {
          console.log('Next part received!');        // ADDED
          if (data) { file.size += data.length; }
          // trigger "file data" event
          if (options.onFileUploadData) { options.onFileUploadData(file, data); }
        });

And the difference between Ubuntu and development server is the last chunk of data. In both environments Next part received! shows up but on development server done doesn’t - which may suggest that the ‘finish’ event is not emitted.

Can it be multer or busboy? Can you give me some advice where to look further? What else could I trace?

Thanks!

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:2
  • Comments:59 (9 by maintainers)

github_iconTop GitHub Comments

7reactions
a9urvcommented, Jun 7, 2016

We faced this issue while trying to upload images from an iOS app to Node.js/Express/Multer via an Nginx reverse proxy. While a majority of the images went through fine, a few specific ones would just not upload. It wasn’t a size issue as well since all images were of similar size and it wasn’t the largest ones which had this problem. It was exactly as @droppedoncaprica has described earlier in this issue - the file was written to the temp location used by Multer but the control was not handed to next.

What finally worked for us was placing all the text fields in the multipart post request before the image file field - i.e. making the image file the last part of the multipart post request. Since then no upload failures. Hope this helps.

Nginx: 1.4.6 Node.js: 0.10.25 Multer: 1.0.0

4reactions
nikonovakcommented, Apr 21, 2016

Just to clarify. In my case the above didn’t work. The solution that did work was adding client_max_body_size to the location portion of the virtual config file for nginx responsible for the proxy settings.

/etc/nginx/conf.d/virtual.conf … server { server_name example.com; location / { client_max_body_size 100m; proxy_pass http://127.0.0.1:3000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; proxy_request_buffering off; } }

Hope this helps someone, NiKO

Read more comments on GitHub >

github_iconTop Results From Across the Web

File upload sometimes hangs - multer, busboy, or something else?
I encountered some strange problem while using multer - sometimes it hangs while uploading the file. When I am testing this behavior on...
Read more >
Unexpected end of form error when using Multer
If the user first selects one file, then changes their mind and selects another, uploadData.append is executed for both files. Not sure if...
Read more >
Express multer middleware
Multer is a node.js middleware for handling multipart/form-data , which is primarily used for uploading files. It is written on top of busboy...
Read more >
Multer/Node File Upload Works Perfectly For Files <20Kb ...
Actual behaviour the 'finish' of busboy event will invoke some function. File upload sometimes hangs - multer, busboy, or something else?
Read more >
Uploadig multiple files with different requirements in multer
Wow, I didn't know we could handle fileSize limit in fileFilter. So does that mean fileFilter knows what the file size is before...
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