Reading Image Files iOS 11.3 and 11.4 in native Webview Cordova/Phonegap app

211 Views Asked by At

In the context of an HTML/Cordova app: Before iOS 11.3 you could use an an input with type="file" in your html to open the Photos library in iOS and select an image. Then using FileReader you could do something with the fetched image in your callback.

Now in 11.3+, when the file loads in your callback: it returns a useless object {isTrusted: true}. See below:

function imageFetchSuccess(files) {
  var file = this.files[0];
  var reader = new FileReader();
  reader.readAsDataURL(file);
  reader.onloadend = function(data) {

    // you used to be able to get your image like this and do something with it
    var img = data.currentTarget.result;

    // but now what's returned for 'data' is {isTrusted: true}
  };
}

I've tried making adjustments with no success. Is it still possible to fetch images using this strategy without using another Cordova plugin?

1

There are 1 best solutions below

0
user1791914 On

So it turns out all you need is var img = reader.result; instead of var img = data.currentTarget.result;