[英]Move S3 objects to another folder in same bucket but with same permissions using C#
I am able to move an object in an S3 bucket from one directory to another directory using C# but unable to copy all current permissions with that object.我可以使用 C# 将 S3 存储桶中的 object 从一个目录移动到另一个目录,但无法使用该 object 复制所有当前权限。
For example, my current object has public access permissions but after moving it to another directory it lost the public read permissions.例如,我当前的 object 具有公共访问权限,但将其移动到另一个目录后,它失去了公共读取权限。
Here is the code I'm using to move objects:这是我用来移动对象的代码:
public void MoveFile(string sourceBucket, string destinationFolder, string file) {
AmazonS3Client s3Client = new AmazonS3Client(ConfigurationHelper.AmazonS3AccessKey, ConfigurationHelper.AmazonS3SecretAccessKey, Amazon.RegionEndpoint.USEast1);
S3FileInfo currentObject = new S3FileInfo(s3Client, sourceBucket, file);
currentObject.MoveTo(sourceBucket + "/" + destinationFolder, file);
}
Here is the output after moving file to another directory:这是将文件移动到另一个目录后的 output:
It lost public "Read" permission.它失去了公开的“阅读”权限。
I've figure out issue myself, by using CopyObject() and DeleteObject() instead of using moveTo inbuild method and that solves my issue,我自己解决了问题,通过使用 CopyObject() 和 DeleteObject() 而不是使用 moveTo inbuild 方法解决了我的问题,
here is the code which really helped me:这是真正帮助我的代码:
CopyObjectRequest copyObjectRequest = new CopyObjectRequest
{
SourceBucket = sourceBucket,
DestinationBucket = sourceBucket + "/" + destinationFolder,
SourceKey = file,
DestinationKey = file,
CannedACL = S3CannedACL.PublicRead,
StorageClass = S3StorageClass.StandardInfrequentAccess,
};
CopyObjectResponse response1 = s3Client.CopyObject(copyObjectRequest);
var deleteObjectRequest = new DeleteObjectRequest
{
BucketName = sourceBucket,
Key = file
};
s3Client.DeleteObject(deleteObjectRequest);
I'm posting answer so it can be helpful for someone!!!我正在发布答案,所以它对某人有帮助!!!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.