Base64 to gallery plugin not working

Hi. I have the following code:

let aaa: Base64ToGalleryOptions = {prefix: "manolete", mediaScanner: false}

    let filePath: string = btoa('file:///storage/6E55-1102/DCIM/Camera/20180705_222745.jpg');
    this.base64.encodeFile('file:///storage/6E55-1102/DCIM/Camera/20180705_222745.jpg').then(base64File => {
      console.log("ssssss" + base64File);
      

    this.base64ToGallery.base64ToGallery(base64File, aaa).then(
      res => console.log('Saved image to gallery ', res),
      err => console.log('Error saving image to gallery ', err)
    );
    }, (err) => {
      console.log("err");
    });

But I get the error: Error saving image to gallery bad base-64

What can I do? Thanks.

I’ve put what this.base64.encodeFile('file:///storage/6E55-1102/DCIM/Camera/20180705_222745.jpg') returned in a website where they decode base64 to img and it worked perfectly.

Hello I find solution I had the same issue but now it’s works you will find my function here

takePic(){
    const options = {
        x: 0,
        y: 0,
        width: window.screen.width,
        height: window.screen.height,
        camera: CameraPreview.CAMERA_DIRECTION.FRONT, //or BACK
        toBack: true,
        tapPhoto: false,
        tapFocus: false,
        previewDrag: false,
        disableExifHeaderStripping: true
    };

    CameraPreview.startCamera(options);

    let base64option : Base64ToGalleryOptions = {
        prefix: 'img',
        mediaScanner: false
    };

CameraPreview.takePicture({}, base64PictureData => {
    let todecode = atob(base64PictureData);

    this.base64ToGallery.base64ToGallery(btoa(todecode), base64option).then(
            res => alert('Saved image to gallery '+ JSON.stringify(res)),
            err => alert('Error saving image to gallery ' + JSON.stringify(err))
          );
    }, error =>{
        alert(JSON.stringify(error));
    });
}

Use atob and btoa functions for encode and decode your picture in base64.
Don’t forget to allow storage access

1 Like