0
嗨,我想保存圖像到s3,但我最近做了,而上傳圖像有一些警告顯示在控制檯上。如何解決它.. 如果圖像存在,我想要替換圖像保存圖像到aws s3,如果圖像存在替換圖像
public String saveImage(MultipartFile file, String imageName) {
try {
String bucketName = "bucket";
AmazonS3 s3client = new AmazonS3Client(
new BasicAWSCredentials("*****", "******"));
TransferManager transferManager = new TransferManager(s3client);
// Otherwise: (Service: Amazon S3; Status Code: 301; Error Code:
// PermanentRedirect)
// s3client.setRegion(Region.getRegion(Regions.EU_WEST_1));
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentDisposition("attachment; filename=" + file.getOriginalFilename());
Upload upload = transferManager.upload(bucketName, imageName, file.getInputStream(), objectMetadata);
upload.waitForUploadResult();
return "https://path-region/" + bucketName + "/" + imageName;
} catch (Exception e) {
return "You failed to upload " + e.getMessage();
}
}
10:31:00,313 WARN [com.amazonaws.services.s3.AmazonS3Client] (s3-transfer-manag
er-worker-1) No content length specified for stream data. Stream contents will
be buffered in memory and could result in out of memory errors.