dropzone upload only one file

前端 未结 6 1301
时光说笑
时光说笑 2021-02-01 02:11

I am using dropzone.js for my drag-drop file upload solution. I want to upload only one file,if i upload second file the first one should be remove and second one should be uplo

6条回答
  •  长情又很酷
    2021-02-01 02:54

    None of these solutions worked for me.

    The maxfilesexceeded event is called too late i.e. after an attempt to add the file.

    Other solutions using this.removeFile(this.files[0]); resulted in a "Uncaught TypeError: Cannot read property 'removeChild' of null". or an infinite loop.

    Solved by -

    maxFiles: 2,
    init: function () {
    
        this.on("addedfile", function (file) {
            if (this.files.length > 1) {
                this.files = this.files.slice(1, 2);                        
            }
        });
    
    }
    

    Works when using dz-clickable (file chooser btn) and drag and drop.

提交回复
热议问题