Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70434

How can remove the data:image part from a base64 string of image type

$
0
0

@sinchan2525 wrote:

Is there a way I could reliably remove the data:image part of a base64 image string? because i want to send to REST api. if have data:image/jpeg;base64 cannot send to platform but if i remove data:image/jpeg;base64 , i can send to platform but cannot see on the mobile. can help me show how i can send to platform without data:image/jpeg;base64 and preview on the mobile with data:image/jpeg;base64. here my code.


  // Camera Function
  pictureFromCamera() {
    const options: CameraOptions = {
      targetHeight: 200,
      targetWidth: 160,
      quality: 60,
      destinationType: this.camera.DestinationType.DATA_URL,
      encodingType: this.camera.EncodingType.JPEG,
      mediaType: this.camera.MediaType.PICTURE,
      correctOrientation: false,
      saveToPhotoAlbum: true
    }

    this.capturePhoto(options);
  }


  // Added PictureSourceType.PHOTOLIBRARY to access from gallery.
  pictureFromGallery() {

    const options: CameraOptions = {
      targetHeight: 200,
      targetWidth: 160,
      quality: 60,
      destinationType: this.camera.DestinationType.DATA_URL,
      encodingType: this.camera.EncodingType.JPEG,
      sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
      mediaType: this.camera.MediaType.PICTURE,
      correctOrientation: true,
      saveToPhotoAlbum: true
    }

    this.capturePhoto(options)
  }

  async capturePhoto(options: CameraOptions) {
    try {
      //Result is a base64 image but can be changed to use a filepath.
      const result = await this.camera.getPicture(options)

      //Append result to image to display in view
      //this.repData.data_image = `data:image/jpeg;base64,${result}`;
      this.repData.data_image = `${result}`;



    }
    catch (e) {
      console.error(e);
    }
  }

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70434

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>