![](/img/trans.png)
[英]How to move all files of folder from another folder to same S3 bucket in script elixir
[英]Move S3 objects to another folder in same bucket but with same permissions using C#
我可以使用 C# 將 S3 存儲桶中的 object 從一個目錄移動到另一個目錄,但無法使用該 object 復制所有當前權限。
例如,我當前的 object 具有公共訪問權限,但將其移動到另一個目錄后,它失去了公共讀取權限。
這是我用來移動對象的代碼:
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);
}
這是將文件移動到另一個目錄后的 output:
它失去了公開的“閱讀”權限。
我自己解決了問題,通過使用 CopyObject() 和 DeleteObject() 而不是使用 moveTo inbuild 方法解決了我的問題,
這是真正幫助我的代碼:
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);
我正在發布答案,所以它對某人有幫助!!!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.