目标:
我有一个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");
}
}