D.Cristi
D.Cristi

Reputation: 177

How to stop upload a second image on dropzone?

I have this sample:

link

CODE HTML:

<div class="dropzone dz-clickable" id="myDrop">
        <div class="dz-default dz-message" data-dz-message="">
                <span>Upload or drag patient photo here</span>
        </div>
</div>

CODE JS:

    Dropzone.autoDiscover = false;
    var myDropzone = new Dropzone("div#myDrop", {
        acceptedFiles:  ".png,.jpg",
        addRemoveLinks: true,
        url: "#"
    });

    var fileName = $('#profilePicture').val();
    var mockFile = { name: fileName, size: 12345 };
myDropzone.options.addedfile.call(myDropzone, mockFile);
myDropzone.options.thumbnail.call(myDropzone, mockFile, "https://lh3.googleusercontent.com/-eubcS91wUNg/AAAAAAAAAAI/AAAAAAAAAL0/iE1Hduvbbqc/photo.jpg?sz=104");

How do I disable uploading of images if there is already a file?

I want something like:

if(image exist){
   disabled upload
}else{
   enabled upload
}

How can I do this in my example? I need a variable to store if there is a file or not?

Thanks in advance!

Upvotes: 1

Views: 520

Answers (1)

Pedram
Pedram

Reputation: 16575

Use maxFiles.

maxFiles:1,
init: function() {
      this.on("maxfilesexceeded", function(file) {
            this.removeAllFiles();
            this.addFile(file);
      });
}    

From DropZone.js

CodePen

Upvotes: 1

Related Questions