I making a sell&buy app with Ionic 2. On new sell I need to show images to add fro sale.
I’m using PhotoLibrary Cordova Plugin to retrive images from android storage.
this.photoLibrary.requestAuthorization().then(() => {
this.photoLibrary.getLibrary().subscribe({
next: library => {
this.photos = library;
},
error: err => { },
complete: () => { console.log("could not get photos"); }
});
}).catch(err => console.log("permissions weren't granted"));
Code from Photo Library
I also added:
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">
to my index.html
file.
<allow-navigation href="*" />
and <allow-navigation href="file://*/*" />
to my config.xml
file.
From No local image showing in view on device
I show photos as follow:
<div class='photos' *ngIf='photos'>
<div class='photo' *ngFor='let photo of photos;'>
<img src="file://{{photo.photoURL}}" alt="{{photo.fileName}}">
</div>
</div>
And on my device I get:
First image without
meta http-equiv
and allow-navigation
on index.html and config.xml respectively.Second image is an
ion-list
showing ID’s and names of each image just to ensure PhotoLibrary was working as expected.Third image after add
meta http-equiv
and allow-navigation
I also did read that I need image URI to base64 string on How to load image from android local storage
Is it necessary? Am I doing something wrong? Did I forgot something?