9

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 ...

2
  • 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/dndfiles Commented Mar 27, 2014 at 7:53
  • I tried your given link but that not worked ... Commented Mar 27, 2014 at 8:11

1 Answer 1

22

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;
      };
   }
}
Sign up to request clarification or add additional context in comments.

2 Comments

how did you convert from ArrayBuffer to [] byte?
but the onload called after some time only

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.