Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Image to Binary Data or String in Javascript

I am working on uploading image file to TWITPIC using XMLHttp Request on a Chrome Extension . I need to send the image as payload. Is there a way to do this ? I found this link Convert an image into binary data in javascript But that works on image tags. i need a way to specify image file path and upload image to TWITPIC.

I came to know about FileReader API with HTML 5. Is there any way to work using that??. It should work on a local file.

Does Chrome Extension support FileReader API without running a localhost server ??

like image 300
Ram Avatar asked Feb 09 '26 16:02

Ram


1 Answers

I found the answer myself. Chrome Extensions does support FileReader API of HTML 5. So just the code below works simple.

  var reader = new FileReader();
  reader.readAsDataURL(f);
like image 101
Ram Avatar answered Feb 12 '26 16:02

Ram