コード例 #1
0
        public List <string> GetBucketList()
        {
            List <string> output = new List <string>();

            S3Request request = new S3Request(this);

            request.Method   = S3Request.RequestMethod.rmGet;
            request.Resource = "/";

            S3Response response = null;

            response = request.Perform();

            XmlDocument doc = new XmlDocument();

            doc.Load(response.GetResponseStream());
            response.Close();

            XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);

            nsmgr.AddNamespace("s3", doc.LastChild.NamespaceURI); //"http://s3.amazonaws.com/doc/2006-03-01/");

            XmlNodeList xmlBuckets = doc.SelectNodes("/s3:ListAllMyBucketsResult/s3:Buckets/s3:Bucket/s3:Name", nsmgr);

            foreach (XmlNode xmlBucketName in xmlBuckets)
            {
                output.Add(xmlBucketName.InnerText);
            }
            return(output);
        }
コード例 #2
0
        public void CreateBucket(string bucketName)
        {
            S3Request request = new S3Request(this);

            request.Resource = "/" + bucketName;
            request.Method   = S3Request.RequestMethod.rmPut;

            S3Response response = null;

            try
            {
                response = request.Perform(null);
            }
            catch (S3Exception ex)
            {
                // Check for "BucketAlreadyOwnedByYou" server code, which is okay.
                if (ex.Code != "BucketAlreadyOwnedByYou")
                {
                    throw ex;
                }
            }

            if (response != null)
            {
                response.Close();
            }
        }
コード例 #3
0
        public void DeleteObject(string path)
        {
            S3Request request = new S3Request(this);

            request.Resource = GetPathForObject(path);
            request.Method   = S3Request.RequestMethod.rmDelete;
            S3Response response = request.Perform(null);

            response.Close();
        }
コード例 #4
0
        // Important: Caller must close the returned Stream!
        public Stream GetObject(string path)
        {
            S3Request request = new S3Request(this);

            request.Resource = GetPathForObject(path);
            request.Method   = S3Request.RequestMethod.rmGet;
            S3Response response = request.Perform();

            return(response.GetResponseStream());
        }
コード例 #5
0
        public void PutObject(string path, Stream stream, string encryptionKey)
        {
            S3Request request = new S3Request(this);

            request.Resource      = GetPathForObject(path);
            request.Method        = S3Request.RequestMethod.rmPut;
            request.EncryptionKey = encryptionKey;
            S3Response response = request.Perform(stream);

            response.Close();
        }
コード例 #6
0
        public List<string> GetBucketList()
        {
            List<string> output = new List<string>();

            S3Request request = new S3Request(this);
            request.Method = S3Request.RequestMethod.rmGet;
            request.Resource = "/";

            S3Response response = null;
            response = request.Perform();

            XmlDocument doc = new XmlDocument();
            doc.Load(response.GetResponseStream());
            response.Close();

            XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
            nsmgr.AddNamespace("s3", doc.LastChild.NamespaceURI); //"http://s3.amazonaws.com/doc/2006-03-01/");

            XmlNodeList xmlBuckets = doc.SelectNodes("/s3:ListAllMyBucketsResult/s3:Buckets/s3:Bucket/s3:Name", nsmgr);
            foreach(XmlNode xmlBucketName in xmlBuckets)
                output.Add(xmlBucketName.InnerText);
            return output;
        }
コード例 #7
0
        public List <string> GetObjectList(string prefix, ref string marker, int maxEntries, string delimiter, ReceiveContentsDelegate contentsDelegate, ReceivePrefixDelegate prefixDelegate)
        {
            bool          cancelled = false; // True if we have been asked to stop (not presently used).
            bool          truncated = false; // True if there were too many entries to list in one go.
            string        lastKey   = marker;
            List <string> output    = new List <string>();

            do
            {
                string signPath = "/";
                if (IsUS)
                {
                    signPath += bucket;
                }
                string path         = signPath + "?prefix=" + HttpUtility.UrlEncode(pathPrefix + prefix);
                int    prefixLength = (pathPrefix + prefix).Length;

                if (marker.Length > 0)
                {
                    path += "&marker=" + HttpUtility.UrlEncode(marker);
                }
                if (delimiter != null && delimiter.Length > 0)
                {
                    path += "&delimiter=" + HttpUtility.UrlEncode(delimiter);
                }

                S3Request request = new S3Request(this);
                request.Resource = path;
                request.Method   = S3Request.RequestMethod.rmGet;
                S3Response response = request.Perform();

                XmlDocument doc = new XmlDocument();
                doc.Load(response.GetResponseStream());
                response.Close();
                XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
                nsmgr.AddNamespace("s3", doc.LastChild.NamespaceURI); //"http://s3.amazonaws.com/doc/2006-03-01/");

                XmlNode truncatedNode = doc.SelectSingleNode("//s3:IsTruncated", nsmgr);
                truncated = truncatedNode.InnerText.ToUpper().StartsWith("T");

                XmlNodeList contentNodes = doc.SelectNodes("//s3:Contents", nsmgr);
                foreach (XmlNode contentNode in contentNodes)
                {
                    string key = contentNode.SelectSingleNode("./s3:Key", nsmgr).InnerText;
                    if (contentsDelegate != null)
                    {
                        contentsDelegate(key.Remove(0, prefixLength));
                    }
                    lastKey = key;
                }
                XmlNodeList prefixNodes = doc.SelectNodes("//s3:CommonPrefixes/s3:Prefix", nsmgr);
                if (prefixDelegate != null)
                {
                    foreach (XmlNode prefixNode in prefixNodes)
                    {
                        prefixDelegate(prefixNode.InnerText.Remove(0, prefixLength));
                    }
                }
            } while (truncated && (maxEntries == 0 || output.Count < maxEntries) && !cancelled);

            marker = truncated ? lastKey : "";
            return(output);
        }
コード例 #8
0
		public void CreateBucket(string bucketName)
		{
			S3Request request = new S3Request(this);
			request.Resource = "/" + bucketName;
			request.Method = S3Request.RequestMethod.rmPut;

            S3Response response = null;

            try
            {
                response = request.Perform(null);
            }
            catch (S3Exception ex)
            {
                // Check for "BucketAlreadyOwnedByYou" server code, which is okay.
                if (ex.Code != "BucketAlreadyOwnedByYou")
                    throw ex;
            }

            if(response != null)
    			response.Close();
		}
コード例 #9
0
 public void DeleteObject(string path)
 {
     S3Request request = new S3Request(this);
     request.Resource = GetPathForObject(path);
     request.Method = S3Request.RequestMethod.rmDelete;
     S3Response response = request.Perform(null);
     response.Close();
 }
コード例 #10
0
 public void PutObject(string path, Stream stream, string encryptionKey)
 {
     S3Request request = new S3Request(this);
     request.Resource = GetPathForObject(path);
     request.Method = S3Request.RequestMethod.rmPut;
     request.EncryptionKey = encryptionKey;
     S3Response response = request.Perform(stream);
     response.Close();
 }
コード例 #11
0
 // Important: Caller must close the returned Stream!
 public Stream GetObject(string path)
 {
     S3Request request = new S3Request(this);
     request.Resource = GetPathForObject(path);
     request.Method = S3Request.RequestMethod.rmGet;
     S3Response response = request.Perform();
     return response.GetResponseStream();
 }
コード例 #12
0
        public List<string> GetObjectList(string prefix, ref string marker, int maxEntries, string delimiter, ReceiveContentsDelegate contentsDelegate, ReceivePrefixDelegate prefixDelegate)
        {
            bool cancelled = false; // True if we have been asked to stop (not presently used).
            bool truncated = false; // True if there were too many entries to list in one go.
            string lastKey = marker;
            List<string> output = new List<string>();
            do
            {
                string signPath = "/";
                if (IsUS)
                    signPath += bucket;
                string path = signPath + "?prefix=" + HttpUtility.UrlEncode(pathPrefix + prefix);
                int prefixLength = (pathPrefix + prefix).Length;

                if (marker.Length > 0)
                    path += "&marker=" + HttpUtility.UrlEncode(marker);
                if (delimiter != null && delimiter.Length > 0)
                    path += "&delimiter=" + HttpUtility.UrlEncode(delimiter);
                
                S3Request request = new S3Request(this);
                request.Resource = path;
                request.Method = S3Request.RequestMethod.rmGet;
                S3Response response = request.Perform();

                XmlDocument doc = new XmlDocument();
                doc.Load(response.GetResponseStream());
                response.Close();
                XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
                nsmgr.AddNamespace("s3", doc.LastChild.NamespaceURI); //"http://s3.amazonaws.com/doc/2006-03-01/");

                XmlNode truncatedNode = doc.SelectSingleNode("//s3:IsTruncated", nsmgr);
                truncated = truncatedNode.InnerText.ToUpper().StartsWith("T");

                XmlNodeList contentNodes = doc.SelectNodes("//s3:Contents", nsmgr);
                foreach (XmlNode contentNode in contentNodes)
                {
                    string key = contentNode.SelectSingleNode("./s3:Key", nsmgr).InnerText;
                    if(contentsDelegate != null)
                        contentsDelegate(key.Remove(0, prefixLength));
                    lastKey = key;
                }
                XmlNodeList prefixNodes = doc.SelectNodes("//s3:CommonPrefixes/s3:Prefix", nsmgr);
                if(prefixDelegate != null)
                    foreach (XmlNode prefixNode in prefixNodes)
                        prefixDelegate(prefixNode.InnerText.Remove(0, prefixLength));

            } while (truncated && (maxEntries == 0 || output.Count < maxEntries) && !cancelled);

            marker = truncated ? lastKey : "";
            return output;
        }