Can't display local images Android [ionic2]


#1

Typescript code:

ImagePicker.getPictures({ quality: 100, maximumImagesCount: 1}).then(results =>
{
  this.image = results[0];
});

HTML:
<p>Image selected: {{ image }}</p> <img [src]="image" style="background: red; min-width: 10px; min-height: 10px;">

After i choose my photo page looks like this: ( there’s no photo :frowning: )

Am I doing it the right way?


#2

are you putting your images in the assets folder? (what version of Ionic are you using?)


#3

No I’m not putting images in the assets folder, photos needs to be loaded dynamically by ImagePicker from ionic-native.
How can I check version of ionic2?


#4

Sorry - I misread your question and didn’t realise you were picking images.

BTW the version of Ionic that your project depends on will be in your package.json file.


#5

Thank you :slight_smile: I solved problem by using File.readAsDataURL from ionic-native, I simply replaced previous typescript code (from first post) with:

ImagePicker.getPictures({ quality: 100, maximumImagesCount: 1}).then(results =>
{
File.readAsDataURL(results[0]).then(value => this.image = value, reason => this.failInfo = "Fail: " + reason);
});


#6

I currently facing the same issue. The way you’ve used readAsDataURL doesn’t match the definition in Ionic2 doc.

readAsDataURL(path, file)
Read file and return data as a base64 encoded data url. A data url is of the form: data:[][;base64].

So my question is, what is the path, the file? I try to pass one parameters, but it doesnt work.