使用Dropzone.js使用Sails.js 0.10和Skipper上载多个文件

ArV*_*Van 5 file-upload dropzone.js sails.js skipper

我的sails应用程序中有多个文件上传的问题.我试图用Dropzone.js实现多个文件上传,我的后端是Sails v0.10.0-rc8.

现在,当我通过dropzone上传一些文件时,我发现在多次上传的情况下,它会在请求中发送带有单独params的文件.参数名称是'photo[0]', 'photo[1]', 'photo[2]',....我在控制器中获取这样的文件:

req.file(file).upload(function (err, files) {

    // save the file

});
Run Code Online (Sandbox Code Playgroud)

但是当提交的文件超过一个时,请求将被传递给控制器​​,然后从请求中解析并存储所有文件,因此我的控制器中只有一个文件.

有没有人遇到过这个问题?也许在船长体解析器中不支持多个文件上传和不同的请求参数?因为当我在一个属性('photo')中提交多个文件时,所有这些文件都会被处理并传递给控制器​​.

sgr*_*454 8

如果您以异步方式遍历参数名称,这应该可以工作,例如:

async.map(paramNames, function(file, cb) {

    req.file(file).upload(function (err, files) {

        // save the file, and then:
        return cb(err, files);

    });

}, function doneUploading(err, files) {

       // If any errors occurred, show server error
       if (err) {return res.serverError(err);}
       // Otherwise list files that were uploaded
       return res.json(files);

});
Run Code Online (Sandbox Code Playgroud)

我能够成功地测试它.

  • 但是如何从 req.conf 获取文件参数。? (在上面的例子中。 paramNames ) (2认同)