Image cropper doesn't return anything if image loaded from file


#1

Hi,

I am working with image cropper plugin https://www.npmjs.com/package/nativescript-imagecropper . I tried demo app it works fine. After I tried it with image picker plugin https://github.com/NativeScript/nativescript-imagepicker and it worked perfectly fine as well (here is working example):

let context = imagepicker.create({
    mode: "single" 
});
context
.authorize()
.then(function() {
  return context.present();
})
.then((selection) => {
  selection.forEach((selected) => {
    selected.getImage()
    .then((imageSource) => {
      this.imageCropper.show(imageSource).then((args) => {
        if(args.image !== null){  
          let folder = fs.knownFolders.temp();
          var path = fs.path.join(folder.path, "savedImage.png");
          var saved = args.image.saveToFile(path,'png');
        }
      })
   
    });
  });
}).catch(function (e) {
    console.log(e);
});

But when I tried to implement with media file picker plugin https://github.com/jibon57/nativescript-mediafilepicker, I am having issues. Image is displayed in the cropper, I can edit the image, but as soon as I click “done”, cropper disappears(as it should be ) but I don’t get any response in console or args value and the value is not saved.

Here is code which is not working:

let options: MediaFilepickerOptions = {
  android: {
    mxcount: 1,
    enableImagePicker: true,
    enableVideoPicker: false,
    enableCameraSupport: false,

    },
  ios: {
    allowsMultipleSelection: false,
    //	title: "Album",
    showCameraButton: false,
    autoSelectCameraImages: true,
  }
};

this.mediafilepicker = new Mediafilepicker();
this.mediafilepicker.on("getFiles",  (res: any) => {

let files = res.files;

if (files.length > 0) {

  files = files.split(",");

    files.forEach(file => {

      let img = imageSource.fromFile(file);

      this.imageCropper.show(img, this.cropperOptions).then((args) => {
        console.log("response");
        console.dir(args)

        if(args.image !== null){  
            let folder = fs.knownFolders.temp();
            var path = fs.path.join(folder.path, "savedImage.png");
            var saved = args.image.saveToFile(path,'png');
      
        }
      })
    })
  }
})
this.mediafilepicker.startFilePicker(options);

Do you have any idea why it is not working? Any advice or help is highly appreciated. Thank you?


#2

@manojdcoder Do you have any idea how to solve this problem?