Search code examples
cordovaionic2ionic3ionic-native

ionic save base64 string as image in galary


   ngOnInit(){

        this.photos=[];
      }

      takePhotos(){

        const options: CameraOptions = {

          quality: 30,
          destinationType: this.camera.DestinationType.DATA_URL,   
          encodingType: this.camera.EncodingType.JPEG,
          mediaType: this.camera.MediaType.PICTURE,
        }
        this.camera.getPicture(options).then((imageData) => {
         // imageData is either a base64 encoded string or a file URI
         // If it's base64:
         this.base64Image = 'data:image/jpeg;base64,' + imageData;

         this.photos.push(this.base64Image);
         this.photos.reverse();
        }, (err) => {
         // Handle error
        });
      }

ionic app with camera plugin img clicked and displayed on screen , how to save this base64 string as images in galary and also get path of each img saved? Can any body describe with a simple example?


Solution

  •   const options: CameraOptions = {
      quality: 30,
      destinationType: this.camera.DestinationType.DATA_URL,   
      encodingType: this.camera.EncodingType.JPEG,
      mediaType: this.camera.MediaType.PICTURE,
      saveToPhotoAlbum : true
    }
    

    Just Add this line saveToPhotoAlbum : true and it started saving saving images in galary.