Dropzone max文件大小超出事件

AVM*_*AVM 2 html javascript jquery dropzone.js

我在我的表单中使用dropzone进行图片上传.我想显示一条警告消息,并在用户选择超出配置限制的文件时删除添加的文件.这是我的配置:

Dropzone.options.myDropzone = { 
      paramName: 'file',
      url: "http://someurl",
      clickable: true,
      enqueueForUpload: true,
      autoProcessQueue: false,
      uploadMultiple: true,
      parallelUploads: 5,
      maxFiles: 1,
      maxFilesize: .06,
      maxThumbnailFilesize: .06,
      acceptedMimeTypes: 'image/*',
      addRemoveLinks: true,
      dictDefaultMessage: 'Drag your images here',
      init: function() {
           console.log('init');
           this.on("maxfilesexceeded", function(file){
                alert("No more files please!");
                this.removeFile(file);
            });

    }
};
Run Code Online (Sandbox Code Playgroud)

我试图为'maxfilesizeexceeded'事件注册一个监听器,但它没有触发.我想对'maxfilesexceeded'采取类似的行动.这可能吗?

Luk*_*uka 15

我刚刚使用Error事件在我的脚本上试了一下.这样我得到一条错误消息,文件再次被删除.这是你想要的?

    this.on("error", function(file, message) { 
                alert(message);
                this.removeFile(file); 
    });
Run Code Online (Sandbox Code Playgroud)

  • 请注意:在“maxfilesexceeded”事件之前,“error”事件也会被触发。如果未定义“错误”事件,则仅触发“maxfilesexceeded”。我建议始终检查“错误”事件的“消息”参数是什么。旁注:"error" 事件获得第三个参数 "xhr",当请求期间未发生错误时,该参数为 typeof 'undefined',上传期间发生错误时为 typeof 'object'(通常为 Internal Error 500 服务器) -边)。 (3认同)