0

Is it possible to turn an image into a base64 string with these restrictions,

  1. Image is coming from <input type="file"/>
  2. No internet connection
  3. Mobile Browser

I know I can download an image and convert it using <canvas>, but is it possible to access the image before it's uploaded? If this is not possible I am going to write a PhoneGap plugin.

Thanks!

Edit-

Got this working using the FileReader API. Here's the relivant code,

var reader = new FileReader();
reader.onload = function(theFile) {
    var base64Image = theFile.srcElement.result;
};

// Read in the image file as a data URL.
reader.readAsDataURL(image.fileElement.dom.files[0]);
4

1 回答 1

1

拦截submit表单上的事件,并读取那里的数据。如果需要,您可以中止提交,并将数据保存在本地。

于 2013-02-13T20:55:52.480 回答