D.Cristi
D.Cristi

Reputation: 177

How to add a default image in the dropzone?

I have this sample:

link

What I want to do is that when the page loads, there was already a charged image

CODE JS:

Dropzone.autoDiscover = false;
var myDropzone = new Dropzone("div#myDrop", {
    acceptedFiles: "image/*",
    maxFiles:1,
    addRemoveLinks: true,
    init: function() {
        this.on("maxfilesexceeded", function(file){
            this.removeFile(file);
            alert("No more files please!");
        });
    },
    url: "#"
});

CODE HTML:

<div class="dropzone dz-clickable" id="myDrop">
                                 <div class="dz-default dz-message" data-dz-message="">
                                      <span>Drag and upload your profile photo</span>
                                 </div>
                        </div>

Is there any possibility to load a picture from the first? Without the added user

Thanks in advance!

Upvotes: 3

Views: 7168

Answers (1)

Cold Head Skillet
Cold Head Skillet

Reputation: 81

This should work for you:

    Dropzone.autoDiscover = false;
    var myDropzone = new Dropzone("div#myDrop", {
    acceptedFiles: "image/*",
    maxFiles:1,
    addRemoveLinks: true,
    init: function() {

            var thisDropzone = this;
            var mockFile = { name: 'Name Image', size: 12345, type: 'image/jpeg' };
            thisDropzone.emit("addedfile", mockFile);
            thisDropzone.emit("success", mockFile);
            thisDropzone.emit("thumbnail", mockFile, "https://example.com")

            this.on("maxfilesexceeded", function(file){
            this.removeFile(file);
            alert("No more files please!");
            });

          }, 
    url :  " # " 
});

Upvotes: 4

Related Questions