我有以下(例如简化的)角度指令,它创建一个放置区
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';
});
}
}
}]);
正如你所看到的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");
}]
}
这是文档上所说的sending
event
在发送每个文件之前调用。获取 xhr 对象和 formData 对象作为第二个和第三个参数,以便您可以修改它们(例如添加 CSRF 令牌)或添加其他数据。
EDIT
我暂时放弃了程序化方法。我有两个表单提交到同一端点,一个是仅发布的常规表单,一个是 dropzone 表单。两者都有效,所以我认为这不是端点的问题,而是我如何处理“发送”事件的问题。
//Receives the POST var just fine
form(action="http://127.0.0.1:3000/uploads", method="post", id="mydz")
input(type="hidden", name="additionaldata", value="1")
input(type="submit")
//With this one I can get the POST var
form(action="http://127.0.0.1:3000/uploads", method="post", id="mydz2", class="dropzone")
input(type="hidden", name="additionaldata", value="1")