如何在Amazon S3存储桶中重命名文件? [英] How to rename a file in Amazon S3 Bucket?
问题描述
我正在尝试重命名S3存储桶中的文件。这是一个代码段
I am trying to rename a file in S3 Bucket. Here is a code snippet
S3Object s3Obj = getS3Client().getObject(new GetObjectRequest(getBucketName(), fileName));
//Error in Above Line itself
getS3Client().putObject(getBucketName(), newFileName, s3Obj.getObjectContent(), s3Obj.getObjectMetadata());
private AmazonS3 getS3Client(){
AWSCredentials myCredentials = new BasicAWSCredentials(AccessKey,SecretKey);
AmazonS3 s3client = new AmazonS3Client(myCredentials);
return s3client;
}
所以,我收到此错误,
调试[main] request.handleErrorResponse(748)|收到的错误响应:com.amazonaws.services.s3.model.AmazonS3Exception:状态代码:403,AWS服务:空,AWS请求ID:AD2F31F1133A650E,AWS错误代码:AccessDenied。
DEBUG [main] request.handleErrorResponse(748) | Received error response: com.amazonaws.services.s3.model.AmazonS3Exception: Status Code: 403, AWS Service: null, AWS Request ID: AD2F31F1133A650E, AWS Error Code: AccessDenied.
我无法获取s3object本身。我将如何获得S3对象并将其重命名的任何建议或想法。
感谢您的帮助。
I am unable to get the s3object itself. Any suggestions or ideas how I will get S3 Object and rename it. Thanks in Anticipation for you help.
推荐答案
直接重命名S3对象不可能
通过复制并删除原始对象来重命名对象
Rename objects by copying them and deleting the original ones
您可以使用例如
CopyObjectRequest copyObjRequest = new CopyObjectRequest(bucketName,
keyName, bucketName, destinationKeyName);
s3client.copyObject(copyObjRequest);
s3client.deleteObject(new DeleteObjectRequest(bucketName, keyName));
这篇关于如何在Amazon S3存储桶中重命名文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!