I have some javascript code that allows users to drag and drop files in IE.
The problem I have is that they would like the file deleted after being dragged, but I can't seem to get the file path, just the name.
I have seen many references to e.dataTransfer.files[0].path
, but it always es back as 'undefined'
when I try it.
Any ideas why e.dataTransfer.files[0].path
does not work, or how I can get the file path?
$(document).ready(function (ex) {
var holder = document.getElementById('holder');
holder.ondragover = function () { this.className = 'hover'; return false; };
holder.ondrop = function (e) {
e.preventDefault();
var file = e.dataTransfer.files[0];
var path = e.dataTransfer.files[0].path;
fileArray.push(file);
//alert(e.target.id);
var reader = new FileReader();
reader.readAsDataURL(file);
};
});
I have some javascript code that allows users to drag and drop files in IE.
The problem I have is that they would like the file deleted after being dragged, but I can't seem to get the file path, just the name.
I have seen many references to e.dataTransfer.files[0].path
, but it always es back as 'undefined'
when I try it.
Any ideas why e.dataTransfer.files[0].path
does not work, or how I can get the file path?
$(document).ready(function (ex) {
var holder = document.getElementById('holder');
holder.ondragover = function () { this.className = 'hover'; return false; };
holder.ondrop = function (e) {
e.preventDefault();
var file = e.dataTransfer.files[0];
var path = e.dataTransfer.files[0].path;
fileArray.push(file);
//alert(e.target.id);
var reader = new FileReader();
reader.readAsDataURL(file);
};
});
Share
Improve this question
edited Nov 15, 2019 at 15:58
Ru Chern Chong
3,75613 gold badges35 silver badges43 bronze badges
asked Nov 15, 2019 at 15:31
J.CartJ.Cart
5722 gold badges9 silver badges25 bronze badges
1
- For security reasons browsers do not allow this, i.e. JavaScript in browser has no access to the File System – diego orellana Commented Nov 15, 2019 at 15:57
3 Answers
Reset to default 10that's not possible for a web app, but if your users would run an app on their machine, you could build an electron app. inside electron you get the e.dataTransfer.files[0].path
property, which you can then use to delete the file.
https://www.electronjs/
The file doesn't have property path
.
You can experiment with it here and the plete list of file properties can be found here.
To read the file one uses FileReader as you did, without using the path
explicitly.
After trying everything I could find, I am of the opinion that it is not possible.