0

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

Mary
  • 45
  • 8
  • Please, add the code as an actual code snippet in the question, don't put a picture that contains code, that way this question can be indexed better. Also, could you please gice us more information about which is the library you arr using? (i assume its some plugin you loaded right?) – Alejandro Vales Mar 09 '19 at 09:55
  • You mentioned 5.0.0 version - ionic 3 does not support those. You have to add @4 after plugin name when installing plugins to get latest stable for v3 – Sergey Rudenko Mar 09 '19 at 17:11
  • Hello @SergeyRudenko! Could you add a comment to the main thread? It seems to me as the solution – Mary Mar 12 '19 at 17:09

2 Answers2

0

After reading through the answer to me it seems like the dependencies could not be properly installed or missing the reference to them when building the app. The code seems to be correct at first glance. You need anyhow to upgrade ionic to version 4 as it's seen also that ionic v3 had issues with the camera in some other posts. "ionic 3 does not support those plugins"

This question has a similar issue and it got fixed by installing again the proper dependency versions https://stackoverflow.com/a/54436891/4229159

Otherwise, if you isolate just the camera in a small app made from the scratch, does it still yield the same error in V4? (Only supported version)

Alejandro Vales
  • 2,816
  • 22
  • 41
-1

Since you are using Ionic 3. You need to make sure you install and import plugins according to documentation:

Please note this is for Ionic 4: https://ionicframework.com/docs/native/image-picker

Install instructions:

ionic cordova plugin add cordova-plugin-telerik-imagepicker npm

install @ionic-native/image-picker

This is for Ionic 3:

ionic cordova plugin add cordova-plugin-telerik-imagepicker --variable PHOTO_LIBRARY_USAGE_DESCRIPTION="your usage message" npm install --save @ionic-native/image-picker@4

Please note @4 that helps npm to install relevant plugin for Ionic v3.

Also note that import statements will differ:

Ionic 4 has:

import { ImagePicker } from '@ionic-native/image-picker/ngx';

Ionic 3 has:

import { ImagePicker } from '@ionic-native/image-picker';

To remove plugins:

cordova plugin list

then

cordova plugin remove PLUGIN_NAME

then install proper plugin for your framework version.

Community
  • 1
  • 1
Sergey Rudenko
  • 8,809
  • 2
  • 24
  • 51