Amazon.S3.AmazonS3Client.PutCORSConfigurationAsync C# (CSharp) Метод

PutCORSConfigurationAsync() публичный Метод

Initiates the asynchronous execution of the PutCORSConfiguration operation.
public PutCORSConfigurationAsync ( PutCORSConfigurationRequest request, System cancellationToken = default(CancellationToken) ) : Task
request PutCORSConfigurationRequest Container for the necessary parameters to execute the PutCORSConfiguration operation.
cancellationToken System /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. ///
Результат Task
        public Task<PutCORSConfigurationResponse> PutCORSConfigurationAsync(PutCORSConfigurationRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new PutCORSConfigurationRequestMarshaller();
            var unmarshaller = PutCORSConfigurationResponseUnmarshaller.Instance;

            return InvokeAsync<PutCORSConfigurationRequest,PutCORSConfigurationResponse>(request, marshaller, 
                unmarshaller, cancellationToken);
        }

Same methods

AmazonS3Client::PutCORSConfigurationAsync ( string bucketName, CORSConfiguration configuration, System cancellationToken = default(CancellationToken) ) : Task
AmazonS3Client::PutCORSConfigurationAsync ( PutCORSConfigurationRequest request, PutCORSConfigurationResponse>.AmazonServiceCallback callback, AsyncOptions options = null ) : void
AmazonS3Client::PutCORSConfigurationAsync ( string bucketName, CORSConfiguration configuration, PutCORSConfigurationResponse>.AmazonServiceCallback callback, AsyncOptions options = null ) : void

Usage Example

        private async Task CreateCloudFrontBucket(string bucketName)
        {
            using (
                var client = new AmazonS3Client(cfConfigurationProvider.AccessKey, cfConfigurationProvider.SecretKey,
                    cfConfigurationProvider.RegionEndpoint))
            {
                await client.PutBucketAsync(bucketName);
                await
                    client.PutCORSConfigurationAsync(bucketName,
                        new CORSConfiguration
                        {
                            Rules =
                            {
                                new CORSRule
                                {
                                    AllowedHeaders = {"Authorization"},
                                    AllowedMethods = {"GET"},
                                    AllowedOrigins = {"*"},
                                    MaxAgeSeconds = 3000
                                }
                            }
                        });

                var policy = new BucketPolicy
                {
                    Version = "2012-10-17",
                    Statement =
                        new Statement
                        {
                            Sid = "AddPerm",
                            Effect = "Allow",
                            Principal = "*",
                            Action = "s3:GetObject",
                            Resource = $"arn:aws:s3:::{bucketName}/*"
                        }
                };
                await client.PutBucketPolicyAsync(bucketName, JsonConvert.SerializeObject(policy));
            }
        }
AmazonS3Client