简体   繁体   English

使用 C# 将 S3 对象移动到同一存储桶中但具有相同权限的另一个文件夹

[英]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.

相关问题 如何在脚本 elixir 中将文件夹的所有文件从另一个文件夹移动到同一个 S3 存储桶 - How to move all files of folder from another folder to same S3 bucket in script elixir 将多个文件从一个文件夹复制到同一 S3 存储桶中的另一个文件夹 - Copying multiple files from one folder to another in the same S3 bucket 使用 Java (Amazon S3) 将 all.txt 文件从一个 object 复制到另一个但在同一个存储桶中 - Copy all .txt files from one object to another but in the same bucket using Java (Amazon S3) 如何通过一些简短的方式将所有文件和文件夹从一个文件夹移动到另一个 php 中的 S3 存储桶? - How to move all files and folder from one folder to another of S3 bucket in php with some short way? 使用 boto3 在 Amazon S3 上的文件夹之间移动文件(指定的存储桶不存在错误) - Move files between folder on Amazon S3 using boto3 ( The specified bucket does not exist error) 如何使用 Glue 作业将 JSON 从 s3 转换为 CSV 文件并将其保存在同一个 s3 存储桶中 - How to convert JSON to CSV file from s3 and save it in same s3 bucket using Glue job 如何将指定字节范围内的多个对象从 S3 存储桶复制/移动到另一个存储桶? - How can I copy/move multiple objects from a S3 bucket within specified byte-ranges to another bucket? 无法使用 boto3 从 s3 存储桶中读取并写入同一存储桶中的不同文件 - Unable to read from s3 bucket and write to same bucket a different file using boto3 使用 CLI 使 S3 存储桶权限对“所有人”公开访问 - Make an S3 Bucket Permissions Public Access to 'Everyone' using CLI 使用 boto3 在 S3 存储桶中移动对象的最快方法 - Fastest way to move objects within an S3 bucket using boto3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM