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

标签 javascript dropzone.js

我以这种方式使用 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>

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

最佳答案

这是一个使用 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
        });
    }
}

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

关于javascript - 上传所有文件后的 dropzone 操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22872789/

相关文章:

javascript - for 循环可以递增/递减一个以上吗?

javascript - 当我多次调用 requestAnimationFrame 时会发生什么

javascript - 使用 Dropzone 通过 Node multer 上传多个文件时出现 LIMIT_UNEXPECTED_FILE 问题

javascript - 我如何将 csrf_token 包含到 dropzone Post 请求(Django)

javascript - 在 Dropzone.js 中如何设置我们可以上传的最小图像分辨率?接受不起作用

javascript - Google Places API 中具有关联 html_attributions 的地点或 place_id(用于测试目的)是什么?

javascript - 选项卡内容未按预期工作

javascript - dropzone.js 是否可以在预览中显示文件名?

javascript - dropzone js onclick提交文件上传

javascript - 在d3中的动态折线图中添加轴