我无法通过使用以下方法部署在Amazon Elastic Beanstalk上的Spring Boot应用程序将图像上传到S3:
@Autowired
private AmazonS3Client amazonS3Client;
amazonS3Client.setEndpoint(S3_REGION_ENDPOINT);
amazonS3Client.putObject(new PutObjectRequest(S3_BUCKET_NAME, key, fileToUpload));
日志显示以下错误:
Caused by: java.io.IOException: Permission denied
at java.io.UnixFileSystem.createFileExclusively(Native Method)
at java.io.File.createNewFile(File.java:1012)
at com.g2m.persistence.image.service.FileArchiveService.convertFromMultiPart(FileArchiveService.java:91)
at com.g2m.persistence.image.service.FileArchiveService.saveFileToS3(FileArchiveService.java:44)
但是当尝试使用本地端点(在本地运行Spring Boot)上传图像时,我设法成功将图像上传到S3并检索它。
知道如何解决这个问题?它与S3权限有关或什么都没有?
答案 0 :(得分:0)
在我看来,您没有正确实例化S3客户端。您可以检查在实例化时是否提供了正确的凭据吗?
像
这样的东西AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
amazonS3Client = new AmazonS3Client(credentials);