I have multipart form in my Sails.js project which submits 2 different files (first audio then image) along with some text params. In most cases with rather small files, everything works fine. But when I tried a bigger audio file (33MB) I got empty files array for my image field in the receiver. Here is some code.
The Controller:
var uploadParamNames = ['audio', 'image'];
async.map(uploadParamNames,
function (file, cb) {
sails.log(req.file(file)._files)
req.file(file).upload(
{
adapter: require('skipper-gridfs'),
uri: sails.config.connections.mongoConnection.url + '.' + file
},
function (err, files) {
// save the file, and then:
return cb(err, files);
});
}, function doneUploading(err, files) {
...
});
Basicaly here I get the following logs for audio and image:
[ { stream: [Object], status: 'bufferingOrWriting' } ]
[]
I tried a debug and found that in case of image field it never reached the line where the file is actually written in prototype.onFile.js
line up.writeFile(part);
.
Also the debug log prints the following:
Parser: Read a chunk of textparam through field `_csrf`
Parser: Read a chunk of textparam through field `ss-name`
Parser: Read a chunk of textparam through field `ss-desc`
Parser: Read a chunk of textparam through field `ss-category`
Parser: Read a chunk of textparam through field `ss-language`
Parser: Read a chunk of textparam through field `ss-place`
Parser: Read a chunk of textparam through field `ss-place-lat`
Parser: Read a chunk of textparam through field `ss-place-lon`
Acquiring new Upstream for field `audio`
Tue, 13 Oct 2015 10:52:54 GMT skipper Set up "maxTimeToWaitForFirstFile" timer for 10000ms
Tue, 13 Oct 2015 10:52:58 GMT skipper passed control to app because first file was received
Tue, 13 Oct 2015 10:52:58 GMT skipper waiting for any text params
Upstream: Pumping incoming file through field `audio`
Parser: Done reading textparam through field `_csrf`
Parser: Done reading textparam through field `ss-name`
Parser: Done reading textparam through field `ss-desc`
Parser: Done reading textparam through field `ss-category`
Parser: Done reading textparam through field `ss-language`
Parser: Done reading textparam through field `ss-tags`
Parser: Done reading textparam through field `ss-place`
Parser: Done reading textparam through field `ss-place-lat`
Parser: Done reading textparam through field `ss-place-lon`
Tue, 13 Oct 2015 10:53:11 GMT skipper Something is trying to read from Upstream `audio`...
Tue, 13 Oct 2015 10:53:11 GMT skipper Passing control to app...
Tue, 13 Oct 2015 10:53:16 GMT skipper maxTimeToWaitForFirstFile timer fired- as of now there are 1 file uploads pending (so it's fine)
debug: [ { stream: [Object], status: 'bufferingOrWriting' } ]
Tue, 13 Oct 2015 10:53:41 GMT skipper .upload() called on upstream
Acquiring new Upstream for field `image`
Tue, 13 Oct 2015 10:53:46 GMT skipper Set up "maxTimeToWaitForFirstFile" timer for 10000ms
debug: []
Not sure why, but it seems the control is already passed to the app before image file is written. Again this only happens with a larger audio file. Is there a way to fix this?
EDIT:
More debugging showed that the receivedFirstFileOfRequest
listener is called before image file is written. Which is logical, because it actually listens for first file upload, but what to do with next files?
EDIT: Ah... the file doesn't need to bee very large at all. A 29KB file passes and a 320KB does not...