Reputation: 655
I need to get image name as well as base64 image when user select an image from photo library.I am using cordova Camera plugin to get image from gallery,but i am not getting image name and base64 image at the same time.
// to get base64 image
Camera.getPicture({
destinationType: Camera.DestinationType.DATA_URL,
sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
targetWidth: 1000,
targetHeight: 1000
}).then((imageData) => {
// imageData is a base64 encoded string
this.base64Image = "data:image/jpeg;base64," + imageData;
alert("this.base64Image="+this.base64Image);
}, (err) => {
console.log(err);
});
//to get image URL
Camera.getPicture({
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
targetWidth: 1000,
targetHeight: 1000
}).then((imagePath) => {
// imageData is a base64 encoded string
this.imagePath = imagePath;
alert("this.imagePath="+this.imagePath);
}, (err) => {
console.log(err);
});
How can i combine both of these call in single click?
Upvotes: 1
Views: 3209
Reputation: 184
Documentation says Camera.DestinationType : enum, can be used one at a time as FILE_URI or DATA_URL or NATIVE_URI
But if you want both base64 and file path, you can convert image to base64 in angularjs
Upvotes: 1