File upload sometimes hangs - multer, busboy, or something else?
See original GitHub issueHI!
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:
- Created 9 years ago
- Reactions:2
- Comments:59 (9 by maintainers)
Top GitHub Comments
We faced this issue while trying to upload images from an
iOS
app toNode.js/Express/Multer
via anNginx
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 byMulter
but the control was not handed tonext
.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
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