How to get file url from ondrop event in javascript

I am running the following code for the bootloader that I am doing.

holder.ondrop = function (e) {
    e.preventDefault();
    console.log(e);
}

I want the user to be able to drag the file from the desktop to the web browser, and then I want to capture his location so that he can manually download it (don't want to download via javascript) My question is, however, how do I get the client location from the file from events so i can put it in <input type="file">?

Thank.

+5
source share
2 answers

The input file field can be considered as a normal input field, and its value can be selected as follows.

<input id="inputid" type="file" dropzone="..."> 

holder.ondrop = function (e) {
    e.preventDefault();
    var path = $('#inputid').val();
    //split the string at the lastIndexOf '/' to get filename 
    console.log(e);
}
+2
source

mozilla dataTransfer ,

:

holder.ondrop = function (e) {
    e.preventDefault();
    if(e.dataTransfer && e.dataTransfer.files.length != 0){
        var files = e.dataTransfer.files //Array of filenames
        files[0]; //the first file in the list

        // code to place file name in field goes here...

    }else{
        // browser doesn't support drag and drop.
    }

    console.log(e);
}

mozilla, , .

+2

All Articles