Assumption: A local HTML/Javascript webpage that has access to file://
At the start of a drag on a draggable HTML element, in the event handler function dragStart(e)
, how do I add a File object so that it is recognized as a file and ends up in the dataTransfer.files
list?
Ex:
function dragStart(e){
var file = getSomeFileObjFromSomewhere();
e.originalEvent.dataTransfer.effectAllowed = "all";
e.originalEvent.dataTransfer.setData("file", file);
console.log("\nFiles:");
i = 0;
var files = e.originalEvent.dataTransfer.files,
len = files.length;
for (; i < len; i++) {
console.log("\nIndex: " + i + "\nFilename: " + files[i].name);
console.log("Type: " + files[i].type);
console.log("Size: " + files[i].size + " bytes");
console.dir(files[i]);
}
}
Specifically, it needs to work on Chrome/Chromium. And, we can assume that the file exists on the local drive. Basically, I want the same data available then when a file is dragged from Windows Explorer to a HTML page on an element that is droppable.
I know that this exists in Chrome:
e.originalEvent.dataTransfer.setData("DownloadURL", fileType + ":" + name + ":" + filePath);
which downloads the file. But this is not what I want, because I want to assume that this is an existing file and that the original file must be accessed.
var file = getSomeFileObjFromSomewhere();
what is purpose of setting file object atevent.dataTransfer
? What are you trying to achieve? – Duganhtml
documents? Or drag a file from user file manager UI at OS to anhtml
document? – Dugan