使用SDK写入S3没有错误但没有文件

时间:2017-05-30 13:58:56

标签: java amazon-s3

当我手动将文件上传到S3时,我必须对其进行加密并且工作正常,我正在尝试对我使用服务器端加密的SDK执行相同的操作。我没有看到任何错误,但我也没有看到该文件。

AmazonS3Client s3Client = new AmazonS3Client(new DefaultAWSCredentialsProviderChain());
AmazonS3URI uri = new AmazonS3URI("https://s3.amazonaws.com/xyz/abc");
File file = new File("/home/ec2-user/abc");

PutObjectRequest putRequest = new PutObjectRequest(uri.getBucket(), uri.getKey(), file);

ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setServerSideEncryption(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
putRequest.setMetadata(objectMetadata);

PutObjectResult response = s3Client.putObject(putRequest);
System.out.println("Uploaded object encryption status is " + response.getContentMd5());

1 个答案:

答案 0 :(得分:0)

我认为您的URI不正确:self.edgesForExtendedLayout = UIRectEdge() self.extendedLayoutIncludesOpaqueBars = false self.automaticallyAdjustsScrollViewInsets = false 您需要在某处提供存储桶名称 - 它应该位于AmazonS3URI uri = new AmazonS3URI("https://s3.amazonaws.com/xyz/abc");之前。

最好只明确指定存储桶名称和密钥:

s3.amazonaws part