Nic*_*ise 6 node.js angularjs dropzone.js
我有以下(例如简化)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 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")
Run Code Online (Sandbox Code Playgroud)
Nic*_*ise 18
好吧,我实际上已经弄明白了,多亏了在新用户创建后使用Dropzone.js上传,发送标题
该sending事件:
myDropZone.on('sending', function(file, xhr, formData){
formData.append('userName', 'bob');
});
Run Code Online (Sandbox Code Playgroud)
相反,由于formData.userName = 'bob'某种原因不起作用.
| 归档时间: |
|
| 查看次数: |
10964 次 |
| 最近记录: |