dropzone自定义缩略图

时间:2019-03-08 19:29:32

标签: javascript jquery dropzone.js react-dropzone

我设法让dropzone在客户端/服务器(django)上正常工作,但是,我一直在为所有上载使用默认缩略图。

所以,我有一些非常简单的html配置,如下所示:

<form  method="post" 
    enctype="multipart/form-data" 
    action="{% url 'upload' %}"
  class="dropzone"
  id="myAwesomeDropzone">
  {% csrf_token %}
</form>

然后我就这样拥有我的JS(我知道0个JS和JQuery,所以请多多包涵):

    <script type="text/javascript">
    // "myAwesomeDropzone" is the camelized version of the HTML element's ID
     Dropzone.options.myAwesomeDropzone = {
     paramName: "file_field", // The name that will be used to transfer the file
      acceptedFiles: ".zip",
      createImageThumbnails: false,
      addRemoveLinks: false,
      maxFilesize: 1000, // MB
    };
    </script>

如您所见,我只接受zip文件,因此希望在上传文件时使用zip图标。现在,我看到dropzone的作者已经提供了一些脚本来完成此here

但是,我无法完成这项工作。我尝试了例如:

<script type="text/javascript">
// "myAwesomeDropzone" is the camelized version of the HTML element's ID
Dropzone.options.myAwesomeDropzone = {
  paramName: "file_field", // The name that will be used to transfer the file
  acceptedFiles: ".zip",
  createImageThumbnails: false,
  addRemoveLinks: false,
  maxFilesize: 1000, // MB
  
myAwesomeDropzone.on("addedfile", function(file_field) {
  if (!file_field.type.match(/image.*/)) {
    // This is not an image, so Dropzone doesn't create a thumbnail.
    // Set a default thumbnail:
    myAwesomeDropzone.emit("thumbnail", file_field, "https://cdn2.iconfinder.com/data/icons/file-names-22/512/50-512.png");

    // You could of course generate another image yourself here,
    // and set it as a data url.
  }
})


};
</script>

我不是JS还是JQ专家,我想知道是否有人可以指出正确的方向来解决这个问题。

0 个答案:

没有答案