我在我的Sails.js项目中有多部分表单,它提交了2个不同的文件(第一个音频然后图像)以及一些文本参数。在大多数情况下,文件相当小,一切正常。但是当我尝试更大的音频文件( 33MB )时,我在接收器中为我的图像字段获取了空文件数组。 这是一些代码。
控制器:
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) {
...
});
基本上这里我得到了以下音频和图像日志:
[ { stream: [Object], status: 'bufferingOrWriting' } ]
[]
我尝试了调试,发现在图像字段的情况下,它从未到达文件实际写入prototype.onFile.js
行up.writeFile(part);
的行。
此外,调试日志还会打印以下内容:
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: []
不确定原因,但似乎控件已经在写入图像文件之前传递给应用程序。同样,这只发生在更大的音频文件中。有办法解决这个问题吗?
修改
更多调试显示在写入映像文件之前调用receivedFirstFileOfRequest
侦听器。这是合乎逻辑的,因为它实际上会侦听第一个文件上传,但是如何处理下一个文件?
修改 啊......文件根本不需要非常大。 29KB文件通过,320KB不通过......