/// <summary> /// Create a private bucket with the given name. /// </summary> /// <param name="bucketName">Name of the new bucket</param> /// <param name="location">Region</param> /// <param name="cancellationToken">Optional cancellation token to cancel the operation</param> /// <returns> Task </returns> /// <exception cref="InvalidBucketNameException">When bucketName is null</exception> public async Task MakeBucketAsync(string bucketName, string location = "us-east-1", CancellationToken cancellationToken = default(CancellationToken)) { if (bucketName == null) { throw new InvalidBucketNameException(bucketName, "bucketName cannot be null"); } if (location == "us-east-1") { if (this.Region != string.Empty) { location = this.Region; } } // Set Target URL Uri requestUrl = RequestUtil.MakeTargetURL(this.BaseUrl, this.Secure, location); var requestBuilder = new HttpRequestMessageBuilder(HttpMethod.Put, requestUrl, "/" + bucketName); // ``us-east-1`` is not a valid location constraint according to amazon, so we skip it. if (location != "us-east-1") { CreateBucketConfiguration config = new CreateBucketConfiguration(location); requestBuilder.AddXmlBody(config.ToXml()); } var response = await this.ExecuteTaskAsync(this.NoErrorHandlers, requestBuilder, cancellationToken) .ConfigureAwait(false); }
/// <summary> /// Create a private bucket with the given name. /// </summary> /// <param name="bucketName">Name of the new bucket</param> /// <param name="location">Region</param> /// <param name="cancellationToken">Optional cancellation token to cancel the operation</param> /// <returns> Task </returns> /// <exception cref="InvalidBucketNameException">When bucketName is null</exception> public async Task MakeBucketAsync(string bucketName, string location = "us-east-1", CancellationToken cancellationToken = default(CancellationToken)) { if (bucketName == null) { throw new InvalidBucketNameException(bucketName, "bucketName cannot be null"); } if (location == "us-east-1") { if (this.Region != string.Empty) { location = this.Region; } } // Set Target URL Uri requestUrl = RequestUtil.MakeTargetURL(this.BaseUrl, this.Secure, location); SetTargetURL(requestUrl); var request = new RestRequest("/" + bucketName, Method.PUT) { XmlSerializer = new RestSharp.Serializers.DotNetXmlSerializer(), RequestFormat = DataFormat.Xml }; // ``us-east-1`` is not a valid location constraint according to amazon, so we skip it. if (location != "us-east-1") { CreateBucketConfiguration config = new CreateBucketConfiguration(location); request.AddBody(config); } var response = await this.ExecuteTaskAsync(this.NoErrorHandlers, request, cancellationToken).ConfigureAwait(false); }
public void TestBucketConfiguration() { CreateBucketConfiguration config = new CreateBucketConfiguration("us-west-1"); XmlSerializer xs = new XmlSerializer(typeof(CreateBucketConfiguration)); StringWriter writer = new StringWriter(); xs.Serialize(writer, config); Console.WriteLine(writer.ToString()); }
public override RestRequest BuildRequest(RestRequest request) { request.XmlSerializer = new RestSharp.Serializers.DotNetXmlSerializer(); request.RequestFormat = DataFormat.Xml; // ``us-east-1`` is not a valid location constraint according to amazon, so we skip it. if (this.Location != "us-east-1") { CreateBucketConfiguration config = new CreateBucketConfiguration(this.Location); string body = Utils.MarshalXML(config, "http://s3.amazonaws.com/doc/2006-03-01/"); request.AddParameter(new Parameter("text/xml", body, ParameterType.RequestBody)); } if (this.ObjectLock) { request.AddOrUpdateParameter("X-Amz-Bucket-Object-Lock-Enabled", "true", ParameterType.HttpHeader); } return(request); }
internal override HttpRequestMessageBuilder BuildRequest(HttpRequestMessageBuilder requestMessageBuilder) { // ``us-east-1`` is not a valid location constraint according to amazon, so we skip it. if (!string.IsNullOrEmpty(this.Location) && this.Location != "us-east-1") { CreateBucketConfiguration config = new CreateBucketConfiguration(this.Location); string body = utils.MarshalXML(config, "http://s3.amazonaws.com/doc/2006-03-01/"); requestMessageBuilder.AddXmlBody(body); requestMessageBuilder.AddOrUpdateHeaderParameter("Content-Md5", utils.getMD5SumStr(Encoding.UTF8.GetBytes(body))); } if (this.ObjectLock) { requestMessageBuilder.AddOrUpdateHeaderParameter("X-Amz-Bucket-Object-Lock-Enabled", "true"); } return(requestMessageBuilder); }
/// <summary> /// Create a bucket with a given name and canned ACL /// </summary> /// <param name="bucket">Name of the new bucket</param> /// <param name="acl">Canned ACL to set</param> public void MakeBucket(string bucket, Acl acl) { var request = new RestRequest("/" + bucket, Method.PUT); CreateBucketConfiguration config = new CreateBucketConfiguration(this.region); request.AddHeader("x-amz-acl", acl.ToString()); request.AddBody(config); var response = client.Execute(request); if (response.StatusCode == HttpStatusCode.OK) { return; } throw ParseError(response); }
/// <summary> /// Create a private bucket with the given name. /// </summary> /// <param name="bucketName">Name of the new bucket</param> /// <param name="cancellationToken">Optional cancellation token to cancel the operation</param> /// <returns> Task </returns> public async Task MakeBucketAsync(string bucketName, string location = "us-east-1", CancellationToken cancellationToken = default(CancellationToken)) { // Set Target URL Uri requestUrl = RequestUtil.MakeTargetURL(this.BaseUrl, this.Secure); SetTargetURL(requestUrl); var request = new RestRequest("/" + bucketName, Method.PUT); request.XmlSerializer = new RestSharp.Serializers.DotNetXmlSerializer(); request.RequestFormat = DataFormat.Xml; // ``us-east-1`` is not a valid location constraint according to amazon, so we skip it. if (location != "us-east-1") { CreateBucketConfiguration config = new CreateBucketConfiguration(location); request.AddBody(config); } var response = await this.ExecuteTaskAsync(this.NoErrorHandlers, request, cancellationToken); }
/// <summary> /// Create a bucket with a given name and location. /// </summary> /// <param name="bucketName">Name of the new bucket</param> /// <param name="location">Name of the location</param> public void MakeBucket(string bucketName, string location) { var request = new RestRequest("/" + bucketName, Method.PUT); // ``us-east-1`` is not a valid location constraint according to amazon, so we skip it. if (location != "us-east-1") { CreateBucketConfiguration config = new CreateBucketConfiguration(location); request.AddBody(config); } var response = client.Execute(request); if (response.StatusCode == HttpStatusCode.OK) { return; } throw ParseError(response); }