【问题标题】:how to remove current upload file in dropzone?如何删除dropzone中的当前上传文件?
【发布时间】:2016-10-03 11:34:25
【问题描述】:

注意事项:我厌倦了所有与此主题相关的问题和答案。

我想删除 dropzone 中的当前上传文件。我设置了alert('i remove current file'); 我设置了最大大小,任何人都可以上传超过 siz 的文件,然后在这个时候删除。

我的代码 Here

【问题讨论】:

    标签: jquery dropzone.js


    【解决方案1】:

    要从 dropzone 中删除文件,您只需调用 removeFile() 方法,最简单的方法是关闭。

    var myDropzone = new Dropzone("#mydropzone", {
      url: "/file/post",
      acceptedFiles: accept,
      maxFilesize: 0.5,
      uploadMultiple: false,
      createImageThumbnails: false,
      addRemoveLinks: true,
      maxFiles: 3,
      maxfilesexceeded: function(file) {
        this.removeAllFiles();
        this.addFile(file);
      },
      init: function() {
    
        var drop = this; // Closure
    
        this.on('error', function(file, errorMessage) {
          //alert(maxFilesize);
          //this.removeAllFiles();
          if (errorMessage.indexOf('Error 404') !== -1) {
            var errorDisplay = document.querySelectorAll('[data-dz-errormessage]');
            errorDisplay[errorDisplay.length - 1].innerHTML = 'Error 404: The upload page was not found on the server';
          }
          if (errorMessage.indexOf('File is too big') !== -1) {
            alert('i remove current file');
    
            // i remove current file
            drop.removeFile(file);
          }
        });
      }
    
    });
    

    fiddle

    【讨论】:

    • 你好@wallwek。您的代码工作正常。但我仍然会出现一个问题,我上传的 6 个文件大于 6 个时间警报。但我只想单次提醒。你能帮帮我吗。
    • @Sumitpatel 我不认为这是可能的,因为文件的添加方式。即使您一次添加多个文件,文件也会被逐个处理,这会导致每个文件触发一次事件。
    猜你喜欢
    • 2020-01-14
    • 2019-08-31
    • 2017-02-12
    • 2020-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多