I am generating my Html page from database (html tags are stored in database) using sql-server functions .. when generating controls I am easily able to deal with all type input controls but in case of input type "file" I am unable to get bytes of uploaded Image/File , i have a requirement of saving file/image byte into DB . Requirement -- How to get imagebytes from input type File using JavaScript , from onclick event of a input type button ...
-
Could you give an output of image from database? Here is a good article about image file inputs but I don't know, will it help in your case: html5rocks.com/en/tutorials/file/dndfilesAnton– Anton2014-03-27 07:53:35 +00:00Commented Mar 27, 2014 at 7:53
-
I tried your given link but that not worked ...user2322447– user23224472014-03-27 08:11:48 +00:00Commented Mar 27, 2014 at 8:11
Add a comment
|
1 Answer
This took me 8 hours to figure out lol. Here you go :)
function submitForm() {
var fileList = document.getElementById("image").files;
var fileReader = new FileReader();
if (fileReader && fileList && fileList.length) {
fileReader.readAsArrayBuffer(fileList[0]);
fileReader.onload = function () {
var imageData = fileReader.result;
};
}
}
2 Comments
Alex Zanfir
how did you convert from ArrayBuffer to [] byte?
MurugananthamS
but the onload called after some time only