问题描述
我有以下(例如,简化的)角度指令,它创建了一个放置区
I have the following (simplified for example) angular directive which creates a 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';
});
}
}
}]);
您可以看到发送
事件处理程序我正在尝试将用户名( bob)与上传的文件一起发送。但是,由于 req.params
作为空数组返回,我似乎无法在路由中间件中检索到它(我也尝试过 req .body
)。
As you can see the the sending
event handler I'm trying to send the username ("bob") along with the uploaded file. However, I can't seem to retrieve it in my route middleware as req.params
comes back as an empty array (I've also tried 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");
}]
}
以下是文档在发送
事件
编辑
我暂时放弃了编程方法。我有两种形式提交给同一端点,一种是常规形式,仅发布,另一种是dropzone形式。两者都有效,所以我认为这与端点无关,而与我如何处理发送事件无关。
I dropped the programmatic approach for now. I have two forms submitting to the same endpoint, a regular one with just post and a dropzone one. Both work, so I don't think it's an issue with the endpoint rather with how I handle the 'sending' event.
//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")
推荐答案
好的,我已经弄清楚了,这要感谢
OK, I've actually figured it out, thanks to Using Dropzone.js to upload after new user creation, send headers
发送
事件:
myDropZone.on('sending', function(file, xhr, formData){
formData.append('userName', 'bob');
});
与 formData.userName ='bob'$ c $相对c>由于某种原因无法正常工作。
As opposed to formData.userName = 'bob'
which doesn't work for some reason.
这篇关于使用send事件通过编程方式创建的Dropzone发送其他数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!