Ejemplo n.º 1
0
        public async Task MakeBucketAsync(string bucketName, string location = "us-east-1", CancellationToken cancellationToken = default(CancellationToken))
        {
            MakeBucketArgs args = new MakeBucketArgs()
                                  .WithBucket(bucketName)
                                  .WithLocation(location);

            await this.MakeBucketAsync(args, cancellationToken);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create a bucket with the given name.
        /// </summary>
        /// <param name="args">MakeBucketArgs Arguments Object that has bucket info like name, location. etc</param>
        /// <param name="cancellationToken">Optional cancellation token to cancel the operation</param>
        /// <returns> Task </returns>
        /// <exception cref="InvalidBucketNameException">When bucketName is invalid</exception>
        public async Task MakeBucketAsync(MakeBucketArgs args, CancellationToken cancellationToken = default(CancellationToken))
        {
            args.Validate();
            RestRequest request = new RestRequest("/" + args.BucketName, Method.PUT);

            if (string.IsNullOrEmpty(args.Location))
            {
                args.Location = this.Region;
            }
            // Set Target URL for MakeBucket
            Uri requestUrl = RequestUtil.MakeTargetURL(this.BaseUrl, this.Secure, args.Location);

            SetTargetURL(requestUrl);
            // Set Authenticator, if necessary.
            if (string.IsNullOrEmpty(this.Region) && !s3utils.IsAmazonEndPoint(this.BaseUrl) && args.Location != "us-east-1" && this.restClient != null)
            {
                this.restClient.Authenticator = new V4Authenticator(this.Secure, this.AccessKey, this.SecretKey, region: args.Location, sessionToken: this.SessionToken);
            }
            await this.ExecuteTaskAsync(this.NoErrorHandlers, args.BuildRequest(request), cancellationToken);
        }