Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
117
rated 0 times [  122] [ 5]  / answers: 1 / hits: 65841  / 10 Years ago, mon, june 16, 2014, 12:00:00

I'm using the Javascript FileReader to load an image in the browser:



e = e.originalEvent;
e.dataTransfer.dropEffect = 'copy';
this.documentFile = e.dataTransfer.files[0];

var reader = new FileReader();
reader.onloadend = function () {
if (reader.result) {
console.log(reader);
$('#theImage').attr('src', reader.result);
}
};
reader.readAsDataURL(this.documentFile);


This works fine. I now want to get the original filename of the image, but I've got no clue how and looking around the internet I can't find anything either?



Does anybody know how I can get the filename through the FileReader? All tips are welcome!


More From » jquery

 Answers
131

This is prob not the best solution, BUT it worked for me.



var reader = new FileReader();
reader.fileName = file.name // file came from a input file element. file = el.files[0];
reader.onload = function(readerEvt) {
console.log(readerEvt.target.fileName);
};


Not the best answer, but a working one.


[#70552] Friday, June 13, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ignacio

Total Points: 467
Total Questions: 128
Total Answers: 79

Location: Luxembourg
Member since Tue, Mar 14, 2023
1 Year ago
ignacio questions
;