Closed chukwumaokere closed 4 years ago
I have a workaround using the cordova-plugin-camera, since I already use the camera plugin to take photos in my app, I found that I could use some tweaks to the camera options to open the library and select a photo as well. I dont know how well known this method is but it is supported in the documentation, just maybe not well known.
libraryOptions: CameraOptions = {
quality: 100,
destinationType: this.camera.DestinationType.FILE_URI,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE,
sourceType: this.camera.PictureSourceType.PHOTOLIBRARY
}
then use this as your function to launch the Photo Library
this.camera.getPicture(this.libraryOptions).then((imageData) => {
// imageData is either a base64 encoded string or a file URI
// If it's base64 (DATA_URL):
let base64Image = 'data:image/jpeg;base64,' + imageData;
console.log(base64Image);
// TODO: need code to upload to server here.
}, (err) => {
// Handle error
console.error(err);
});
This will do for my use case. It doesnt support picking multiple photos at once though but what you can do is code an intermediate modal that allows users to pick photos from their library and see the photos they've chosen before submitting the photos.
I'm running Ionic 5.4.1 for testing more recently since it didn't work on 4 Ionic: 5.4.1 Cordova: 9.0.0 (cordova-lib@9.0.1) Tested on Android and iOS 13 I followed the instructions to install photolibrary, set up the privoder in app.module.ts and whenever I call the function
I get this error: ` [ng] [console.warn]: "Install the PhotoLibrary plugin: 'ionic cordova plugin add cordova-plugin-photo-library'"
` I've tried a bunch of things:
and everytime I run this app on my test devices (physical devices NOT emulators) I can't seem to get them the library to work. ActionSheet and Camera plugins are working JUST FINE, but the PhotoLibrary seems bugged? Any idea which version I should try/switch to to ensure stability?
i'm running using
ionic serve --devapp
and running Ionic Devapp on my test devices.