当前位置: 首页>>代码示例>>C#>>正文


C# AmazonS3.SetACL方法代码示例

本文整理汇总了C#中AmazonS3.SetACL方法的典型用法代码示例。如果您正苦于以下问题:C# AmazonS3.SetACL方法的具体用法?C# AmazonS3.SetACL怎么用?C# AmazonS3.SetACL使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AmazonS3的用法示例。


在下文中一共展示了AmazonS3.SetACL方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetObjectStorageClass

        /// <summary>
        /// Sets the storage class for the S3 Object's Version to the value
        /// specified.
        /// </summary>
        /// <param name="bucketName">The name of the bucket in which the key is stored</param>
        /// <param name="key">The key of the S3 Object whose storage class needs changing</param>
        /// <param name="version">The version of the S3 Object whose storage class needs changing</param>
        /// <param name="sClass">The new Storage Class for the object</param>
        /// <param name="s3Client">The Amazon S3 Client to use for S3 specific operations.</param>
        /// <seealso cref="T:Amazon.S3.Model.S3StorageClass"/>
        public static void SetObjectStorageClass(string bucketName, string key, string version, S3StorageClass sClass, AmazonS3 s3Client)
        {
            if (sClass > S3StorageClass.ReducedRedundancy ||
                sClass < S3StorageClass.Standard)
            {
                throw new ArgumentException("Invalid value specified for storage class.");
            }

            if (null == s3Client)
            {
                throw new ArgumentNullException("s3Client", "Please specify an S3 Client to make service requests.");
            }

            // Get the existing ACL of the object
            GetACLRequest getACLRequest = new GetACLRequest();
            getACLRequest.BucketName = bucketName;
            getACLRequest.Key = key;
            if(version != null)
                getACLRequest.VersionId = version;
            GetACLResponse getACLResponse = s3Client.GetACL(getACLRequest);

            // Set the storage class on the object
            CopyObjectRequest copyRequest = new CopyObjectRequest();
            copyRequest.SourceBucket = copyRequest.DestinationBucket = bucketName;
            copyRequest.SourceKey = copyRequest.DestinationKey = key;
            if (version != null)
                copyRequest.SourceVersionId = version;
            copyRequest.StorageClass = sClass;
            // The copyRequest's Metadata directive is COPY by default
            CopyObjectResponse copyResponse = s3Client.CopyObject(copyRequest);

            // Set the object's original ACL back onto it because a COPY
            // operation resets the ACL on the destination object.
            SetACLRequest setACLRequest = new SetACLRequest();
            setACLRequest.BucketName = bucketName;
            setACLRequest.Key = key;
            if (version != null)
                setACLRequest.VersionId = copyResponse.VersionId;
            setACLRequest.ACL = getACLResponse.AccessControlList;
            s3Client.SetACL(setACLRequest);
        }
开发者ID:writeameer,项目名称:AWSSDKForNet-extended,代码行数:51,代码来源:AmazonS3Util.cs

示例2: SetWebsiteRedirectLocation

        /// <summary>
        /// Sets the redirect location for the S3 Object's when being accessed through the S3 website endpoint.
        /// </summary>
        /// <param name="bucketName">The name of the bucket in which the key is stored</param>
        /// <param name="key">The key of the S3 Object</param>
        /// <param name="websiteRedirectLocation">The redirect location</param>
        /// <param name="s3Client">The Amazon S3 Client to use for S3 specific operations.</param>
        public static void SetWebsiteRedirectLocation(string bucketName, string key, string websiteRedirectLocation, AmazonS3 s3Client)
        {
            CopyObjectRequest copyRequest;
            SetACLRequest setACLRequest;

            SetupForObjectModification(bucketName, key, null, s3Client, out copyRequest, out setACLRequest);

            copyRequest.WebsiteRedirectLocation = websiteRedirectLocation;
            CopyObjectResponse copyResponse = s3Client.CopyObject(copyRequest);

            if (!string.IsNullOrEmpty(copyResponse.VersionId))
                setACLRequest.VersionId = copyResponse.VersionId;

            s3Client.SetACL(setACLRequest);
        }
开发者ID:Xandertje,项目名称:aws-sdk-net,代码行数:22,代码来源:AmazonS3Util.cs

示例3: SetServerSideEncryption

        /// <summary>
        /// Sets the server side encryption method for the S3 Object's Version to the value
        /// specified.
        /// </summary>
        /// <param name="bucketName">The name of the bucket in which the key is stored</param>
        /// <param name="key">The key of the S3 Object</param>
        /// <param name="version">The version of the S3 Object</param>
        /// <param name="method">The server side encryption method</param>
        /// <param name="s3Client">The Amazon S3 Client to use for S3 specific operations.</param>
        public static void SetServerSideEncryption(string bucketName, string key, string version, ServerSideEncryptionMethod method, AmazonS3 s3Client)
        {
            CopyObjectRequest copyRequest;
            SetACLRequest setACLRequest;

            SetupForObjectModification(bucketName, key, version, s3Client, out copyRequest, out setACLRequest);

            copyRequest.ServerSideEncryptionMethod = method;
            CopyObjectResponse copyResponse = s3Client.CopyObject(copyRequest);

            if (!string.IsNullOrEmpty(copyResponse.VersionId))
                setACLRequest.VersionId = copyResponse.VersionId;

            s3Client.SetACL(setACLRequest);
        }
开发者ID:Xandertje,项目名称:aws-sdk-net,代码行数:24,代码来源:AmazonS3Util.cs

示例4: SetObjectStorageClass

        /// <summary>
        /// Sets the storage class for the S3 Object's Version to the value
        /// specified.
        /// </summary>
        /// <param name="bucketName">The name of the bucket in which the key is stored</param>
        /// <param name="key">The key of the S3 Object whose storage class needs changing</param>
        /// <param name="version">The version of the S3 Object whose storage class needs changing</param>
        /// <param name="sClass">The new Storage Class for the object</param>
        /// <param name="s3Client">The Amazon S3 Client to use for S3 specific operations.</param>
        /// <seealso cref="T:Amazon.S3.Model.S3StorageClass"/>
        public static void SetObjectStorageClass(string bucketName, string key, string version, S3StorageClass sClass, AmazonS3 s3Client)
        {
            CopyObjectRequest copyRequest;
            SetACLRequest setACLRequest;

            SetupForObjectModification(bucketName, key, version, s3Client, out copyRequest, out setACLRequest);

            copyRequest.StorageClass = sClass;
            CopyObjectResponse copyResponse = s3Client.CopyObject(copyRequest);

            if (!string.IsNullOrEmpty(copyResponse.VersionId))
                setACLRequest.VersionId = copyResponse.VersionId;

            s3Client.SetACL(setACLRequest);
        }
开发者ID:Xandertje,项目名称:aws-sdk-net,代码行数:25,代码来源:AmazonS3Util.cs

示例5: ShareFile

 public static void ShareFile(AmazonS3 s3Client, string filekey)
 {
     S3Response response1 = s3Client.SetACL(new SetACLRequest()
     {
         CannedACL = S3CannedACL.PublicRead,
         BucketName = BUCKET_NAME,
         Key = filekey
     });
 }
开发者ID:xescrp,项目名称:breinstormin,代码行数:9,代码来源:S3Engine.cs

示例6: SetServerSideEncryption

        /// <summary>
        /// Sets the server side encryption method for the S3 Object's Version to the value
        /// specified.
        /// </summary>
        /// <param name="bucketName">The name of the bucket in which the key is stored</param>
        /// <param name="key">The key of the S3 Object</param>
        /// <param name="version">The version of the S3 Object</param>
        /// <param name="method">The server side encryption method</param>
        /// <param name="s3Client">The Amazon S3 Client to use for S3 specific operations.</param>
        /// <seealso cref="T:Amazon.S3.Model.S3StorageClass"/>
        public static void SetServerSideEncryption(string bucketName, string key, string version, ServerSideEncryptionMethod method, AmazonS3 s3Client)
        {
            if (null == s3Client)
            {
                throw new ArgumentNullException("s3Client", "Please specify an S3 Client to make service requests.");
            }

            // Get the existing ACL of the object
            GetACLRequest getACLRequest = new GetACLRequest();
            getACLRequest.BucketName = bucketName;
            getACLRequest.Key = key;
            if (version != null)
                getACLRequest.VersionId = version;
            GetACLResponse getACLResponse = s3Client.GetACL(getACLRequest);

            ListObjectsResponse listObjectResponse = s3Client.ListObjects(new ListObjectsRequest()
                .WithBucketName(bucketName)
                .WithPrefix(key)
                .WithMaxKeys(1));

            if (listObjectResponse.S3Objects.Count != 1)
            {
                throw new ArgumentNullException("No object exists with this bucket name and key.");
            }

            // Set the storage class on the object
            CopyObjectRequest copyRequest = new CopyObjectRequest();
            copyRequest.SourceBucket = copyRequest.DestinationBucket = bucketName;
            copyRequest.SourceKey = copyRequest.DestinationKey = key;
            copyRequest.StorageClass = listObjectResponse.S3Objects[0].StorageClass == "STANDARD" ? S3StorageClass.Standard : S3StorageClass.ReducedRedundancy;
            if (version != null)
                copyRequest.SourceVersionId = version;

            copyRequest.ServerSideEncryptionMethod = method;
            // The copyRequest's Metadata directive is COPY by default
            CopyObjectResponse copyResponse = s3Client.CopyObject(copyRequest);

            // Set the object's original ACL back onto it because a COPY
            // operation resets the ACL on the destination object.
            SetACLRequest setACLRequest = new SetACLRequest();
            setACLRequest.BucketName = bucketName;
            setACLRequest.Key = key;
            if (version != null)
                setACLRequest.VersionId = copyResponse.VersionId;
            setACLRequest.ACL = getACLResponse.AccessControlList;
            s3Client.SetACL(setACLRequest);
        }
开发者ID:nburn42,项目名称:aws-sdk-for-net,代码行数:57,代码来源:AmazonS3Util.cs


注:本文中的AmazonS3.SetACL方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。