Ionic 3, Angular CLI 7, Angular 5.
Not able to get an image from the library.
It fails on calling getPicture. I’m getting an error:
“Object(WEBPACK_IMPORTED_MODULE_1__ionic_native_core[“cordova”]) is not a function. (In ‘Object(WEBPACK_IMPORTED_MODULE_1__ionic_native_core[“cordova”])(this, “getPicture”, { “callbackOrder”: “reverse” }, arguments)’, ‘Object(WEBPACK_IMPORTED_MODULE_1__ionic_native_core[“cordova”])’ is an instance of Object)”
I already tried putting all native plugins to version 5.0.0-beta.15 but it doesn’t help.
I've tried both with ImagePicker and Camera plugins but both give same error.
ImagePicker (the plugin is @ionic-native/image-picker) :
let options = {
maximumImagesCount: 1
};
this.imagePicker.getPictures(options).then((results) => {
for (var i = 0; i < results.length; i++) {
this.imgPreview = results[i];
this.base64.encodeFile(results[i]).then((base64File: string) => {
this.regData.avatar = base64File;
}, (err) => {
});
}
}, (err) => { console.log(err); });
Camera (the plugin is @ionic-native/camera):
var sourceType = this.camera.PictureSourceType.PHOTOLIBRARY;
var options = {
quality: 100,
sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
saveToPhotoAlbum: false,
correctOrientation: true
};
this.camera.getPicture(options).then((imagePath) => {
console.log("Img path: " + imagePath);
if (this.platform.is('android') && sourceType === this.camera.PictureSourceType.PHOTOLIBRARY) {
this.filePath.resolveNativePath(imagePath)
.then(filePath => {
let correctPath = filePath.substr(0, filePath.lastIndexOf('/') + 1);
let currentName = imagePath.substring(imagePath.lastIndexOf('/') + 1, imagePath.lastIndexOf('?'));
});
} else {
var currentName = imagePath.substr(imagePath.lastIndexOf('/') + 1);
var correctPath = imagePath.substr(0, imagePath.lastIndexOf('/') + 1);
}
}, (err) => {
console.log(err);
});
Could anyone help me please?
UPD: I downgraded ImagePicker and Base64 to same version as native-core and it seemed to start working. But when I tried to run the app from Ionic DevApp it kept telling me that I should add telerik-imagepicker plugin to cordova but it's already on its list! (yes, I did try to add though). So the error is "plugin_not_installed".
UPD 2: I had to leave this project so unfortunately I don't know what is the solution since I didn't check the idea proposed by Sergey