How to get selected file path in dropzone.js?

Member

by brandy , in category: Javascript , 3 months ago

How to get selected file path in dropzone.js?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by adan , 2 months ago

@brandy 

To get the selected file path in dropzone.js, you can use the addedfile event handler. Here's an example code snippet:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
Dropzone.options.myDropzone = {
  paramName: "file", // The name that will be used to transfer the file
  maxFilesize: 2, // MB
  accept: function(file, done) {
    if (file.name === "justinbieber.jpg") {
      done("Naha, you don't.");
    } else {
      done();
    }
  },
  addedfile: function(file) {
    console.log("File added: " + file.name);
    console.log("File path: " + file.upload.filename);
  }
};


In the addedfile event handler, you can access the file path by using file.upload.filename. This will give you the path of the selected file.