javascript 上传所有文件后的 dropzone 操作

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22872789/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 23:55:57  来源:igfitidea点击:

dropzone action after all files are uploaded

javascriptdropzone.js

提问by user3174311

I'm using dropzonejs this way:

我以这种方式使用 dropzonejs:

<script type="text/javascript">
        jQuery(function($) {
            try 
            {
                $(".dropzone").dropzone({
                    paramName: "file", // The name that will be used to transfer the file
                    maxFilesize: 0.5, // MB
                    uploadMultiple: true,
                    //addRemoveLinks : true,
                    dictDefaultMessage :
                        '<span class="bigger-150 bolder"><i class="icon-caret-right red"></i> Drop files</span> to upload \
                        <span class="smaller-80 grey">(or click)</span> <br /> \
                        <i class="upload-icon icon-cloud-upload blue icon-3x"></i>',
                    dictResponseError: 'Error while uploading file!',               
                    //change the previewTemplate to use Bootstrap progress bars
                    previewTemplate: "<div class=\"dz-preview dz-file-preview\">\n  <div class=\"dz-details\">\n    <div class=\"dz-filename\"><span data-dz-name></span></div>\n    <div class=\"dz-size\" data-dz-size></div>\n    <img data-dz-thumbnail />\n  </div>\n  <div class=\"progress progress-small progress-striped active\"><div class=\"progress-bar progress-bar-success\" data-dz-uploadprogress></div></div>\n  <div class=\"dz-success-mark\"><span></span></div>\n  <div class=\"dz-error-mark\"><span></span></div>\n  <div class=\"dz-error-message\"><span data-dz-errormessage></span></div>\n</div>"
                });
            } 
            catch(e) 
            {
                alert('Dropzone.js does not support older browsers!');
            }
});

    </script>

where exactly can I put a listener do do something (reload/redirect/alert) after ALL files are uploaded?

上传所有文件后,我究竟可以将侦听器放在哪里做某事(重新加载/重定向/警报)?

回答by tarokins

Here is a generic initialisation script using jQuery for Dropzone

这是一个使用 jQuery for Dropzone 的通用初始化脚本

Dropzone.options.myDropZoneForm = {
    url: 'url/here',
    autoProcessQueue: false,
    uploadMultiple: true,
    parallelUploads: 100,       
    addRemoveLinks: true,
    uploadMultiple: true,
    acceptedFiles: 'image/*, audio/*, video/*',
    maxFiles: 10,
    init: function () {
        var thisDropzone = this;

        // just showing some dropped files stats
        var totalFiles = 0, completeFiles = 0;
        this.on('addedfile', function(file){
            totalFiles += 1;
            totalFilesFormatted = totalFiles.toFixed(2);
            $('#showTotalFileCount').html(totalFilesFormatted);
        });
        this.on('removedfile', function(file){
            totalFiles -= 1;
            totalFilesFormatted = totalFiles.toFixed(2);
            $('#showTotalFileCount').html(totalFilesFormatted);
        });
        this.on('maxfilesreached', function(file){
            alert('maxFiles reached');
        });
        this.on('maxfilesexceeded', function(file){
            alert('files dropped exceeded maxFiles');
        });
        this.on("sendingmultiple", function(){
            // event when files are being sent
        });
        this.on("successmultiple", function(files, response) {
            // event when files are successfully uploaded
            // you can return a response string and process it here through 'response'
        });
        this.on("errormultiple", function(files, response) {
          // event when there's an error
        });
    }
}

Hope this helps you iron out things. Cheers!

希望这可以帮助您解决问题。干杯!

回答by Scott

You need the parameter completemultiplewhich is a function that will be called once all files have been uploaded.

您需要一个参数completemultiple,该函数将在所有文件上传后调用。

Also fo interest to you:

还有你感兴趣的:

  • processingmultiple
  • sendingmultiple
  • successmultiple
  • canceledmultiple
  • processingmultiple
  • sendingmultiple
  • successmultiple
  • canceledmultiple

From: http://www.dropzonejs.com/

来自:http: //www.dropzonejs.com/