如何将base64字符串存储/上传为png文件?

时间:2018-03-09 09:17:41

标签: javascript angular image blob

base64字符串是我在控制器中获得的字符串。我试图将其保存为png文件或直接将其上传到S3服务器。但是AWS上传的文件是空白的。

当使用在线base64图像查看器时,该编码字符串可完美地显示图像。这是代码。

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!');
  }
});  
}

0 个答案:

没有答案