The base64 string is what I'm getting in the controller. I'm trying to save it as png file or upload it directly to the S3 server. But the uploaded file is blank on the AWS.
While that encoded string perfectly shows image when using online base64 image viewer. Here is the code.
imageCropped(image: string) {
this.croppedImage = image;
let base64Image = this.croppedImage.split(';base64,').pop();
var the_blob = new Blob([window.atob(base64Image)], {type: 'image/jpg'});
var reader = new FileReader();
var url = URL.createObjectURL(the_blob);
// AWS CONFIGURATIONS
s3.upload({ Key: 'upload_2.png', Bucket: bucketName, Body: the_blob, ContentEncoding: 'base64', ACL: 'public-read' }, function (err, data) {
if (err) {
console.log(err, 'there was an error uploading your file');
} else if (data) {
console.log(data, 'File has been uploaded successfully!');
}
});
}