使用dropzone.js发送其他参数 [英] Sending additional parameter with dropzone.js

查看:381
本文介绍了使用dropzone.js发送其他参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试添加dropzone.js,并且希望将另一个参数与文件一起传递,因此我将隐藏的输入内容放入了form。我可以上传文件,并且可以在Java部分中读取它,但是看不到type_chooser,

I am trying to add dropzone.js and I'd like to pass another parameter with file, so I put hidden input in form . I can upload file and can read it in Java part but I can't read type_chooser,

  ------WebKitFormBoundaryZxF6MCYJpTOLUokN
 Content-Disposition: form-data; name="type_chooser"

 2
 ------WebKitFormBoundaryZxF6MCYJpTOLUokN
 Content-Disposition: form-data; name="file"; filename="isci.xlsx"
 Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

所以,如果我写;

 request.getParameter("type_chooser");

我得到空值

我如何得到type_chooser?

How can I get type_chooser ?

注意:我尝试过;

  dropzone.on("sending,function(file,xhr,data){
     data.append("type_chooser","1");
  });

这会以dropzone形式提供具有隐藏字段的相同输出,它们都发送type_chooser,但我无法在Java中读取它

This gives same output with hidden field in dropzone form, both of them are sending type_chooser but I can't read it in java

推荐答案

您可以将数据与formdata一起附加

You can append data along with the formdata

 $("div#dropzone_profile_photo").dropzone({
            url: "/file-upload/",
            init: function() {
                this.on("sending", function(file, xhr, formData){
                        formData.append("data", "loremipsum");
                });
            }
        });

$("div#dropzone_profile_photo").dropzone({
  url: "/test",
  init: function() {
    this.on("sending", function(file, xhr, formData) {
      formData.append("data", "loremipsum");
      console.log(formData)
    });
  }
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://rawgit.com/enyo/dropzone/master/dist/dropzone.js"></script>
<link rel="stylesheet" href="https://rawgit.com/enyo/dropzone/master/dist/dropzone.css">
<div id="dropzone_profile_photo" style="width:400px;height:400px; background-color:blue"></div>

>

这篇关于使用dropzone.js发送其他参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆