コード例 #1
0
ファイル: GetResponse.cs プロジェクト: njmube/AmazonS3DA
 public GetResponse( WebRequest request )
     : base(request)
 {
     SortedList metadata = extractMetadata( response );
     byte [] data = Utils.slurpInputStream( response.GetResponseStream() );
     this.obj = new S3Object( data, metadata );
 }
コード例 #2
0
 /// <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);
 }
コード例 #3
0
        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));
        }
コード例 #4
0
        /// <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;
        }
コード例 #5
0
        /// <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);
        }
コード例 #6
0
        /// <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);
        }
コード例 #7
0
        /// <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 );
        }