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