Dropzone: prevent file from being added twice

I use dropzone to upload images to the gallery. I send by button. Can I add the same file twice? I am not sure if I check the name, name and size. Here is my code:

<script> var i = 0; Dropzone.options.myDropzone = { init: function() { this.on("addedfile", function(file) { i=++i; 

check file names and files of other files here

 ----------->if(){ myDropzone.removeFile(file); } var inputs = Dropzone.createElement('<div class="dz-image-metadata"><label for="'+i+'_title">Nazov</label><input type="hidden" name="'+i+'_filename" value="'+file.name+'"><input type="text" name="'+i+'_title" value="'+file.name+'" /><label for="">Popis</label><input type="text" name="'+i+'_desc"></div>'); file.previewElement.appendChild(inputs); var removeButton = Dropzone.createElement("<button class=\"dz-button\">Vymazať</button>"); var _this = this; removeButton.addEventListener("click", function(e) { e.preventDefault(); e.stopPropagation(); i=--i; _this.removeFile(file); }); file.previewElement.appendChild(removeButton); }); var myDropzone = this; $("#submit-all").click(function (e) { e.preventDefault(); e.stopPropagation(); myDropzone.processQueue(); i=0; } ); this.on("successmultiple", function(files, response) { console.log(response); }); this.on("complete", function(file) { myDropzone.removeFile(file); }); this.on("errormultiple", function(files, response) { }); }, autoProcessQueue: false, previewsContainer: ".dropzone", uploadMultiple: true, parallelUploads: 25, maxFiles: 25, }; </script> 
+2
javascript multifile-uploader
source share
3 answers

Add these simple lines of code:

 myDropzone.on("addedfile", function(file) { if (this.files.length) { var _i, _len; for (_i = 0, _len = this.files.length; _i < _len - 1; _i++) // -1 to exclude current file { if(this.files[_i].name === file.name && this.files[_i].size === file.size && this.files[_i].lastModifiedDate.toString() === file.lastModifiedDate.toString()) { this.removeFile(file); } } } }); 
+4
source share

Checking the file name and size should be great. I already tested this and it worked almost perfectly for me and did not encounter any problems.

The original thread I landed on was Git issue # 639 , where a member of the community posted their solution to check the name and size.

This trick was also mentioned in a similar post answer .

0
source share
  this.on("addedfile", function (file) { if (this.files.length) { var i, len, pre; for (i = 0, len = this.files.length; i < len - 1; i++) { if (this.files[i].name == file.name) { alert("The Doc.: " + file.name + " is already registered.") return (pre = file.previewElement) != null ? pre.parentNode.removeChild(file.previewElement) : void 0; } } } }); 
0
source share

All Articles