AWS S3:通过Spring服务器从vue将映像上传到S3

时间:2020-08-27 09:39:18

标签: amazon-s3 file-upload

目标: 我有一个Vue前端,允许用户从本地选择图像。
单击“提交”后,它将图像发送到我的spring服务器并上传到s3。
服务器应支持多个请求,因此我使用TransferManager异步上传图像。

问题:
在上传过程中获得体验

例如:com.amazonaws.SdkClientException:无法计算MD5哈希值:

代码: Vue前端:将图像发布到Spring服务器

saveUserProfile() {
  MySpringServerClient.uploadImage(canvas.toDataURL())
    .then(response => {
      ...
    })
    .catch();
}

Spring服务器:

public void uploadImage(@RequestBody UploadImageRequest request) {
    // The image data look like this: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAc......
    String base64Data = request.getImage().split(",")[1];
    File outputFile = new File(base64Data, "output.png");  // tried without split but still failed
    try {
        String fileUrl = awsS3Service.uploadFile(outputFile, "some_file_name.png");
        Upload upload = transferManager.upload("MY_BUCKET_NAME", "MY_KEY_NAME", file);
        upload.waitForCompletion(); // exception here
    } catch (Exception ex)  {
        System.out.println("failed");
    }
}

0 个答案:

没有答案