Esempio n. 1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        AWSAuthConnection conn = new AWSAuthConnection(accessKey, secretKey);

          XmlTextReader r = new XmlTextReader(Request.InputStream);
          r.MoveToContent();
          string xml = r.ReadOuterXml();

          XmlDocument documentToSave = new XmlDocument();
          documentToSave.LoadXml(xml);

          SortedList metadata = new SortedList();
          metadata.Add("title", bucket);
          metadata.Add("Content-Type", "application/xml");
          S3Object titledObject =
           new S3Object(documentToSave.OuterXml, metadata);

          SortedList headers = new SortedList();
          headers.Add("Content-Type", "application/xml");
          headers.Add("x-amz-acl", "public-read");

          conn.put(bucket, documentKey, titledObject, headers);

          Response.Write("saved: " + documentToSave.OuterXml);
    }
Esempio n. 2
0
 public GetResponse( WebRequest request ) :
     base(request)
 {
     SortedList metadata = extractMetadata( response );
     string body = Utils.slurpInputStream( response.GetResponseStream() );
     this.obj = new S3Object( body, 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);
 }
Esempio n. 4
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));
        }
Esempio n. 5
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)));
        }
Esempio n. 6
0
        public bool Copy (ClipItem item) {

            S3Object oItem = new S3Object(item.Data, item.MetaData);
            string copyKey = this.KeyPrefix + "-copy-" + oItem.GetHashCode().ToString(provider);

            try {
                this.Clipboard().put(StorageBase, copyKey, oItem, null);
                this.ClipCopy.Push(item);
                return true;
            } catch (Exception e) {
                throw;
            }
        }
Esempio n. 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 + "/" + HttpUtility.UrlEncode(key), headers, obj);

            request.ContentLength = obj.Data.Length;

            ASCIIEncoding encoding = new ASCIIEncoding();

            byte[] bytes = encoding.GetBytes(obj.Data);
            request.GetRequestStream().Write(bytes, 0, bytes.Length);
            request.GetRequestStream().Close();

            return(new Response(request));
        }
Esempio n. 8
0
        public bool Paste () {
            ClipItem item = this.ClipCopy.Pop();
            string pasteKey = KeyPrefix + "-paste" + item.GetHashCode().ToString(provider);

            S3Object oItem = new S3Object(item.Data, item.MetaData);

            try {
                this.Clipboard().put(StorageBase, pasteKey, oItem, null);
                this.ClipPaste.Push(item);
                return true;
            } catch (Exception e) {
                throw;
            }
        }
Esempio n. 9
0
        public GetResponse(WebRequest request, bool asStream) :
            base(request)
        {
            SortedList metadata = extractMetadata(response);

            if (asStream)
            {
                this.obj = new S3Object(response.GetResponseStream(), metadata);
            }
            else
            {
                string body = Utils.slurpInputStream(response.GetResponseStream());
                this.obj = new S3Object(body, metadata);
            }
        }
Esempio n. 10
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", "?logging", headers, obj, bucket);

            request.ContentLength = loggingXMLDoc.Length;

            ASCIIEncoding encoding = new ASCIIEncoding();

            byte[] bytes = encoding.GetBytes(obj.Data);
            request.GetRequestStream().Write(bytes, 0, bytes.Length);
            request.GetRequestStream().Close();

            return(new Response(request));
        }
Esempio n. 11
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 + "/" + HttpUtility.UrlEncode(key), headers, obj);

            request.ContentLength = aclXMLDoc.Length;

            ASCIIEncoding encoding = new ASCIIEncoding();

            byte[] bytes = encoding.GetBytes(obj.Data);
            request.GetRequestStream().Write(bytes, 0, bytes.Length);
            request.GetRequestStream().Close();

            return(new Response(request));
        }
        /// <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 );
            req.Method = method;

            addHeaders( req, headers );
            if ( obj != null ) addMetadataHeaders( req, obj.Metadata );
            addAuthHeader( req, resource );

            return req;
        }
        /// <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 + "/" + HttpUtility.UrlEncode(key), headers, obj);
            request.ContentLength = aclXMLDoc.Length;

            ASCIIEncoding encoding = new ASCIIEncoding();
            byte[] bytes = encoding.GetBytes(obj.Data);
            request.GetRequestStream().Write(bytes, 0, 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 + "/" + HttpUtility.UrlEncode(key), headers, obj);
            request.ContentLength = obj.Data.Length;

            ASCIIEncoding encoding = new ASCIIEncoding();
            byte[] bytes = encoding.GetBytes( obj.Data );
            request.GetRequestStream().Write( bytes, 0, bytes.Length );
            request.GetRequestStream().Close();

            return new Response( request );
        }
Esempio n. 15
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 WITHOUT BUCKET</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 resourceWithoutBucket, SortedList headers, S3Object obj, string bucket)
        {
            string keyForUrl, keyForEncryption;
            string server = Utils.Host(bucket);

            if (bucket == "" && resourceWithoutBucket == "")
            {
                keyForUrl = "";
                keyForEncryption = "";
            }
            else
            {
                if (server == Utils.DEFAULT_SERVER)
                    keyForUrl = bucket + "/" + resourceWithoutBucket;
                else
                    keyForUrl = resourceWithoutBucket;

                keyForEncryption = bucket + "/" + resourceWithoutBucket;
            }

            string url = makeURL(server, keyForUrl);
            WebRequest req = WebRequest.Create(url);
            if (req is HttpWebRequest)
            {
                HttpWebRequest httpReq = req as HttpWebRequest;
                httpReq.AllowWriteStreamBuffering = false;
                httpReq.Proxy.Credentials = CredentialCache.DefaultCredentials;
            }
            req.Method = method;

            addHeaders(req, headers);
            if (obj != null) addMetadataHeaders(req, obj.Metadata);
            addAuthHeader(req, keyForEncryption);

            return req;
        }
Esempio n. 16
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", "?logging", headers, obj, bucket);
            request.ContentLength = loggingXMLDoc.Length;

            ASCIIEncoding encoding = new ASCIIEncoding();
            byte[] bytes = encoding.GetBytes(obj.Data);
            request.GetRequestStream().Write(bytes, 0, bytes.Length);
            request.GetRequestStream().Close();

            return new Response(request);
        }
Esempio n. 17
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 WITHOUT BUCKET</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 resourceWithoutBucket, SortedList headers, S3Object obj, string bucket)
        {
            string keyForUrl, keyForEncryption;
            string server = Utils.Host(bucket);

            if (bucket == "" && resourceWithoutBucket == "")
            {
                keyForUrl        = "";
                keyForEncryption = "";
            }
            else
            {
                if (server == Utils.DEFAULT_SERVER)
                {
                    keyForUrl = bucket + "/" + resourceWithoutBucket;
                }
                else
                {
                    keyForUrl = resourceWithoutBucket;
                }

                keyForEncryption = bucket + "/" + resourceWithoutBucket;
            }

            string     url = makeURL(server, keyForUrl);
            WebRequest req = WebRequest.Create(url);

            if (req is HttpWebRequest)
            {
                HttpWebRequest httpReq = req as HttpWebRequest;
                httpReq.AllowWriteStreamBuffering = false;
                httpReq.Proxy.Credentials         = CredentialCache.DefaultCredentials;
            }
            req.Method = method;

            addHeaders(req, headers);
            if (obj != null)
            {
                addMetadataHeaders(req, obj.Metadata);
            }
            addAuthHeader(req, keyForEncryption);

            return(req);
        }
Esempio n. 18
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;
        }
Esempio n. 19
0
        public Response put(string bucket, string key, S3Object obj) {
            WebRequest request = makeRequest("PUT", bucket + "/" + encodeKeyForSignature(key), null, obj);
            request.ContentLength = obj.Data.Length;

            ASCIIEncoding encoding = new ASCIIEncoding();
            byte[] bytes = encoding.GetBytes(obj.Data);
            using (Stream _stream = request.GetRequestStream()) {
                _stream.Write(bytes, 0, bytes.Length);
                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));
        }
Esempio n. 21
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);

            req.Method = method;

            addHeaders(req, headers);
            if (obj != null)
            {
                addMetadataHeaders(req, obj.Metadata);
            }
            addAuthHeader(req, resource);

            return(req);
        }