我想将多个图像文件上传到我的服务器 . 在客户端,我使用dropzone.js . 我的后端服务器是sails.js,我想使用formidable来使用进度条更新客户端(我对sails.js和node.js相当新)
这是我的控制器(用打字稿写的)
export var upload = function (req: express.Request, res: express.Response, next) {
var form = new formidable.IncomingForm();
form.parse(req, function (err, fields, files) {
});
form.on('progress', function (bytesReceived, bytesExpected) {
// calculating perscent and logging progress message
});
form.on('error', function (err) {
console.error(err); // --> here I get "Request aborted"
});
form.on('end', function (fields, files) {
// here I save files to disk with fs-extra and I
// send back to client appropriate status
});
}
我一直在错误处理程序中得到“请求中止” . 我已经在stackoverflow和google上进行了一些搜索,但没有找到明确的答案 . 问题似乎与多部分表单数据和用于解析正文的适当表达中间件有关 . 如何设置我的sails.js应用程序,以便在客户端使用dropzone.js上传文件,并在服务器上强大的风帆?
任何帮助将非常感激
1 回答
使用Dropzone和Sails.js,您必须:
在dropzone配置中添加文件名的定义:Dropzone.options.myDropzone = {paramName:“fileName”}
使用此命令获取上传的文件:req.file('fileName') . upload(function(err,uploadedFiles){
});
uploadedFiles包含该文件