Dropzone.js paramName在隐藏输入中未更改

时间:2019-01-26 04:12:59

标签: javascript jquery dropzone.js dropzone

Dropzone.js对我来说还比较新。我试图让它与其余的表单提交(实际上是CMS)一起上传文件。但这不起作用。我可以看到隐藏文件输入没有name属性: enter image description here

这是我的(简化的)HTML的样子:

<div id="ugc1">
    <div class="dz-default dz-message"></div>

    <div class="fallback">
        <input type="file" name="fields[ugc1]">
    </div>
</div>

这是相关的JS / jQuery:

  Dropzone.autoDiscover = false;
  $("#ugc1").dropzone({
    url: "/",
    maxFiles : 1,
    maxFilesize: '3',
    addRemoveLinks: true,
    paramName: 'fields[ugc1]',
    thumbnailWidth: 420,
    thumbnailHeight: 315,
    thumbnailMethod: 'crop',
    resizeWidth: 420,
    resizeHeight: 315,
    resizeMethod: 'crop',
    acceptedFiles: 'image/*',
    // autoProcessQueue: false,
    // previewsContainer: '',
    hiddenInputContainer: 'form',
    dictFileTooBig: 'Please upload a smaller file.',
    success: function (file, response) {
        var imgName = response;
        file.previewElement.classList.add("dz-success");
        console.log("Successfully uploaded :" + imgName);
    },
    error: function (file, response) {
        file.previewElement.classList.add("dz-error");
    },
    init: function() {
      var dropzone1 = this

      // Create the mock file:
      var dzFile1 = $('#ugc1').data("ugc1-file")
      var dzFile1Size = $('#ugc1').data('ugc1-filesize')
      var mockFile1 = { name: dzFile1, size: dzFile1Size };

      if (dzFile1) {
        // Call the default addedfile event handler
        dropzone1.emit("addedfile", mockFile1);

        // And optionally show the thumbnail of the file:
        dropzone1.emit("thumbnail", mockFile1, "/assets/images/ugc/" + dzFile1);
      }
    }
  });

我已将paramName设置为fields[ugc1],因为这就是CMS需要的。但是正如我所提到的,它并没有被添加到隐藏文件输入字段中(我假设它应该被添加)。

不确定要使它正常工作我缺少什么。

0 个答案:

没有答案