简体   繁体   English

使用DropZone.js一对一上传多个文件

[英]Upload multiple files one by one using DropZone.js

Is there any possibility that the multiple files will be uploaded one by one using dropzone.js. 是否有可能使用dropzone.js逐个上传多个文件。 The following is a custom dropzone config script. 以下是自定义的dropzone配置脚本。

Dropzone.options.myDropzone = {
                autoProcessQueue: false,
                parallelUploads: 10,
                addRemoveLinks:true,
                init: function () {
                    var submitButton = document.querySelector("#submit-all");
                    myDropzone = this; // closure
                    submitButton.addEventListener("click", function () {
                        if(myDropzone.getQueuedFiles().length === 0)
                        {
                            alert("Please drop or select file to upload !!!");
                        }
                        else{
                           myDropzone.processQueue(); // Tell Dropzone to process all queued files.
                        } 
                    });
                },
                url: "upload.php"
            };

Right now, it uploads all files at a time which are all in the process queue. 现在,它一次上传所有在进程队列中的所有文件。 Since, the upload file size will be bigger, all files have to upload one by one. 由于上传文件的大小会更大,因此所有文件都必须一个一个地上传。 please help to short out the same. 请帮助短路。

I used this for uploading files one by one. 我用它来一张一张地上传文件。 Hope this helps. 希望这可以帮助。 If you want the complete code according to your functions let me know. 如果您想根据自己的功能编写完整的代码,请告诉我。

startUpload() is called when customer confirms upload of files. 当客户确认文件上传时,将调用startUpload()。

    Dropzone.autoDiscover = false;
    var myDropzone = new Dropzone("#uploadModal", { 
        url: "upload.php", 
        paramName: "file_upload",
        maxFilesize: 1024, 
        maxFiles: 200,
        autoProcessQueue: false
    });

    function startUpload(){
        for (var i = 0; i < myDropzone.getAcceptedFiles().length; i++) {
            myDropzone.processFile(myDropzone.getAcceptedFiles()[i]);
        }
    }

    myDropzone.on('success', function(file, result) {
        try {
            result = JSON.parse(result)
            if (!result.error) {
                if(myDropzone.getQueuedFiles().length === 0 && myDropzone.getUploadingFiles().length === 0){
                    $("#uploadModal"). modal('hide');
                    myDropzone.removeAllFiles(true) ;
                }
            }
            //TODO - 
        } catch (e) {
            //TODO -
        }
    });

You need to set autoProcessQueue to true and parallelUploads to 1 . 您需要将autoProcessQueue设置为true,parallelUploads设置1

Setting autoProcessQueue to true tells dropzone to automatically process the queue. 将autoProcessQueue设置为true会告诉dropzone自动处理队列。 Setting parallelUploads to 1 tells dropzone to only upload one file at a time from the queue. 将parallelUploads设置为1可以指示dropzone一次仅从队列上传一个文件。

Dropzone.options.myDropzone = {
            autoProcessQueue: true,
            parallelUploads: 1,
            addRemoveLinks:true,
            init: function () {
                var submitButton = document.querySelector("#submit-all");
                myDropzone = this; // closure
                submitButton.addEventListener("click", function () {
                    if(myDropzone.getQueuedFiles().length === 0)
                    {
                        alert("Please drop or select file to upload !!!");
                    }
                    else{
                       myDropzone.processQueue(); // Tell Dropzone to process all queued files.
                    } 
                });
            },
            url: "upload.php"
        };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM