public GetResponse( WebRequest request ) : base(request) { SortedList metadata = extractMetadata( response ); byte [] data = Utils.slurpInputStream( response.GetResponseStream() ); this.obj = new S3Object( data, metadata ); }
/// <summary> /// Creates a new bucket. /// </summary> /// <param name="bucket">The name of the bucket to create</param> /// <param name="headers">A Map of string to string representing the headers to pass (can be null)</param> public Response createBucket( string bucket, SortedList headers ) { S3Object obj = new S3Object("", null); WebRequest request = makeRequest("PUT", bucket, headers, obj); request.ContentLength = 0; request.GetRequestStream().Close(); return new Response(request); }
public string put( string bucket, string key, S3Object obj, SortedList headers ) { SortedList metadata = null; if ( obj != null ) { metadata = obj.Metadata; } return generateURL("PUT", bucket + "/" + HttpUtility.UrlEncode(key), mergeMeta(headers, metadata)); }
/// <summary> /// Make a new WebRequest /// </summary> /// <param name="method">The HTTP method to use (GET, PUT, DELETE)</param> /// <param name="resource">The resource name (bucket + "/" + key)</param> /// <param name="headers">A map of string to string representing the HTTP headers to pass (can be null)</param> /// <param name="obj">S3Object that is to be written (can be null).</param> private WebRequest makeRequest( string method, string resource, SortedList headers, S3Object obj ) { string url = makeURL( resource ); WebRequest req = WebRequest.Create( url ); if (req is HttpWebRequest) { HttpWebRequest httpReq = req as HttpWebRequest; httpReq.AllowWriteStreamBuffering = false; } req.Method = method; addHeaders( req, headers ); if ( obj != null ) addMetadataHeaders( req, obj.Metadata ); addAuthHeader( req, resource ); return req; }
/// <summary> /// Write a new logging xml document for a given bucket /// </summary> /// <param name="bucket">The name of the bucket to enable/disable logging on</param> /// <param name="loggingXMLDoc">The xml representation of the logging configuration as a String.</param> /// <param name="headers">A map of string to string representing the HTTP headers to pass (can be null)</param> public Response putBucketLogging(string bucket, string loggingXMLDoc, SortedList headers) { S3Object obj = new S3Object(loggingXMLDoc, null); WebRequest request = makeRequest("PUT", bucket + "?logging", headers, obj); request.ContentLength = loggingXMLDoc.Length; request.GetRequestStream().Write(obj.Bytes, 0, obj.Bytes.Length); request.GetRequestStream().Close(); return new Response(request); }
/// <summary> /// Write a new ACL for a given object /// </summary> /// <param name="bucket">The name of the bucket where the object lives or the /// name of the bucket to change the ACL if key is null.</param> /// <param name="key">The name of the key to use; can be null.</param> /// <param name="aclXMLDoc">An XML representation of the ACL as a string.</param> /// <param name="headers">A map of string to string representing the HTTP headers to pass (can be null)</param> public Response putACL(string bucket, string key, string aclXMLDoc, SortedList headers) { S3Object obj = new S3Object( aclXMLDoc, null ); if ( key == null ) key = ""; WebRequest request = makeRequest("PUT", bucket + "/" + encodeKeyForSignature(key) + "?acl", headers, obj); request.ContentLength = aclXMLDoc.Length; request.GetRequestStream().Write(obj.Bytes, 0, obj.Bytes.Length); request.GetRequestStream().Close(); return new Response(request); }
/// <summary> /// Writes an object to S3. /// </summary> /// <param name="bucket">The name of the bucket to which the object will be added.</param> /// <param name="key">The name of the key to use</param> /// <param name="obj">An S3Object containing the data to write.</param> /// <param name="headers">A map of string to string representing the HTTP headers to pass (can be null)</param> public Response put( string bucket, string key, S3Object obj, SortedList headers ) { WebRequest request = makeRequest("PUT", bucket + "/" + encodeKeyForSignature(key), headers, obj); request.ContentLength = obj.Bytes.Length; request.GetRequestStream().Write(obj.Bytes, 0, obj.Bytes.Length); request.GetRequestStream().Close(); return new Response( request ); }