我的 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 的文件没有...