0

I'm using ngx-image-cropper to crop image but i get cropped image in base64 format because my existing code gets and save files

profileUpload(e): void {
    this.image  = e.target.files[0];
}

but while cropping it is in base64 format

imageCropped(event: ImageCroppedEvent) {
    this.user.photo = event.base64;
    this.cropped = event.base64;
  }

Complete code:

 import { ImageCroppedEvent, ImageTransform } from 'ngx-image-cropper';
    user={ ..
    };
    image: any = '';
    croppedImage: any = '';
    transform: ImageTransform = {};
    scale = 1;
    showCropper = false;
    profilePicUpload(e): void {
        this.imageChangedEvent = e;
        this.image  = e.target.files[0];
      }
    
      imageCropped(event: ImageCroppedEvent) {
        this.user.photo = event.base64;
        this.croppedImage = event.base64.substring(22);
      }
      imageLoaded() {
        this.showCropper = true;
      }
    
    async addImg() {
    
     if(this.image){ 
          const path  = await this.UploadService.uploadFile(this.image);
          await new Promise(f => setTimeout(f, 2000));
          this.user.photo = '';
          this.user.photo += path;
         } 
    }

How will i convert base64 format to file i don't want to use any external library, used this

let File = base64ToFile(this.croppedImage);

but getting Cannot find name 'base64ToFile'.

Any solution Thanks

user3653474
  • 3,393
  • 6
  • 49
  • 135
  • 1
    Does this answer your question? [How to convert Base64 String to javascript file object like as from file input form?](https://stackoverflow.com/questions/35940290/how-to-convert-base64-string-to-javascript-file-object-like-as-from-file-input-f) – Idrizi.A Jul 28 '22 at 07:59
  • You can look at this one: https://stackoverflow.com/questions/58502673/angular-8-parsing-base64-to-file – Ale_Bianco Jul 28 '22 at 08:04

0 Answers0