我有以下(例如简化)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'; }); } } }]);
正如您可以看到发送事件处理程序我正在尝试发送用户名(“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"); }] }
以下是文档对发送事件的说法
Called just before each file is sent. Gets the xhr object and the formData objects as second and third parameters,so you can modify them (for example to add a CSRF token) or add additional data.
编辑
我现在放弃了程序化方法.我有两个表单提交到同一个端点,一个只有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",id="mydz2",class="dropzone") input(type="hidden",value="1")
解决方法
好吧,我真的想通了,多亏了
Using Dropzone.js to upload after new user creation,send headers
发送事件:
myDropZone.on('sending',formData){ formData.append('userName','bob'); });
而不是formData.userName =’bob’,由于某种原因不起作用.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。