我有以下(例如简化)angular指令,它创建了一个dropzone
directives.directive('dropzone', ['dropZoneFactory', function(dropZoneFactory){
'use strict';
return {
restrict: 'C',
link : function(scope, element, attrs){
new Dropzone('#'+attrs.id, {url: attrs.url});
var myDropZone = Dropzone.forElement('#'+attrs.id);
myDropZone.on('sending', function(file, xhr, formData){
//this gets triggered
console.log('sending');
formData.userName='bob';
});
}
}
}]);
Run Code Online (Sandbox Code Playgroud)
正如您所看到的那样,sending事件处理程序我正在尝试发送用户名("bob")以及上传的文件.但是,我似乎无法在我的路由中间件中检索它,因为req.params它作为一个空数组返回(我也尝试过req.body).
我的节点路线
{
path: '/uploads',
httpMethod: 'POST',
middleware: [express.bodyParser({ keepExtensions: true, uploadDir: 'uploads'}),function(request,response){
// comes back as []
console.log(request.params);
//this sees the files fine
console.log(request.files);
response.end("upload complete");
}]
}
Run Code Online (Sandbox Code Playgroud)
以下是文档对该sending事件的评论
在每个文件发送之前调用.获取xhr对象和formData对象作为第二个和第三个参数,以便您可以修改它们(例如添加CSRF标记)或添加其他数据.
编辑
我现在放弃了程序化方法.我有两个表单提交到同一个端点,一个只有post和一个dropzone的表单.两者都有效,所以我认为这不是端点的问题,而是我如何处理'发送'事件.
//Receives the POST …Run Code Online (Sandbox Code Playgroud)