gpt4 book ai didi

Java AWS S3 PutObject 多部分文件

转载 作者:行者123 更新时间:2023-12-01 19:58:23 30 4
gpt4 key购买 nike

我在尝试将图像文件放入 S3 时遇到一些问题,

 exception = "com.amazonaws.SdkClientException";
message = "Unable to calculate MD5 hash: /home/ubuntu/image1517896928.png (No such file or directory)";

我首先在我的服务器上下载 MultipartFile,然后使用我调用 putObject 方法的文件,
因为 S3 putObject 方法采用以下参数 -

putObject(String arg0, String arg1, File arg2) 

这是我的代码-

public String uploadImage(MultipartFile image) throws IOException, InterruptedException{

File localFile = new File(SERVER_HOME_DIRECTORY + image.getOriginalFilename());

AmazonS3 s3client = new AmazonS3Client();
s3client.setRegion(Region.getRegion(Regions.EU_CENTRAL_1));

s3client.putObject(new PutObjectRequest("bucketName", "prefix", localFile));

return "ok";
}

最佳答案

我想建议使用TransferManager,它非常可靠,并且可以为将文件传输到 S3 提供更好的性能。它也是检查上传进度的选项(使用监听器)。

TransferManager

Sample code using TransferManager

TransferManager provides a simple API for uploading content to Amazon S3, and makes extensive use of Amazon S3 multipart uploads to achieve enhanced throughput, performance and reliability.

When possible, TransferManager attempts to use multiple threads to upload multiple parts of a single upload at once. When dealing with large content sizes and high bandwidth, this can have a significant increase on throughput.

关于Java AWS S3 PutObject 多部分文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48699619/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com