Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
7
rated 0 times [  14] [ 7]  / answers: 1 / hits: 21194  / 10 Years ago, sat, november 15, 2014, 12:00:00

i'm currently trying to upload a file to my server. But i'm not really sure how to do this with readAsArrayBuffer. This works if I use readAsBinaryString.



If i try to console.log it only returns 'arrayBuffer: {}'.
After I've tried to upload it, i can see inside post that only a empty object was sent. If I use readAsBinaryString, I see a bunch of binary code.



var file = document.getElementById('my_file').files[0],
reader = new FileReader();

reader.onloadend = function(e){
console.log(e.target.result);
$scope.image = e.target.result;
}

reader.readAsArrayBuffer(file);


How can I see my file, so I know it's working when using readAsArrayBuffer?
If more code is needed let me know! Thanks.


More From » filereader

 Answers
4

If you want to upload am image then you have to convert it into base64 format. You can do it either by using canvas element or by using Filereader.If you are using Filereader then you have to use readAsDataURL()



You can refer MDN for this
https://developer.mozilla.org/en-US/docs/Web/API/FileReader.readAsDataURL



also you can use canvas element
Convert an image to canvas that is already loaded


[#68795] Thursday, November 13, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
luna

Total Points: 698
Total Questions: 114
Total Answers: 93

Location: Israel
Member since Wed, Apr 14, 2021
3 Years ago
luna questions
;