Пример #1
0
        public Stream getStream(string bucket, string key, HeaderList headers)
        {
            WebRequest webRequest =
                BuildWebRequest("GET", bucket + "/" + EncodeKeyForSignature(key), headers);
            WebResponse response = webRequest.GetResponse();

            return(response.GetResponseStream());
        }
Пример #2
0
        public S3Response put(string bucket, string key, S3Content content, HeaderList headers)
        {
            WebRequest webRequest = this.BuildWebRequest("PUT", bucket + "/" + this.EncodeKeyForSignature(key), headers);

            webRequest.ContentLength = (long)content.Bytes.Length;
            Stream requestStream = webRequest.GetRequestStream();

            requestStream.Write(content.Bytes, 0, content.Bytes.Length);
            requestStream.Close();
            return(S3Response.Execute(webRequest));
        }
Пример #3
0
            public override void Close()
            {
                int num = 3;

                for (int i = 0; i < num; i++)
                {
                    bool flag = i == num - 1;
                    try
                    {
                        HeaderList headerList = new HeaderList();
                        headerList.Add("content-type", contentType);
                        headerList.Add("x-amz-acl", "public-read");
                        s3OutputMethod.s3adaptor.put(s3OutputMethod.bucketName,
                                                     s3key,
                                                     new S3Content(ToArray()),
                                                     headerList);
                        break;
                    }
                    catch (WebException)
                    {
                        if (flag)
                        {
                            throw;
                        }
                    }
                    catch (SoapException)
                    {
                        if (flag)
                        {
                            throw;
                        }
                    }
                }

                base.Close();
            }
Пример #4
0
        private WebRequest BuildWebRequest(string method, string objectPath, HeaderList protoHeaders)
        {
            UriBuilder uriBuilder = new UriBuilder("http", "s3.amazonaws.com", 80, objectPath);
            WebRequest webRequest = WebRequest.Create(uriBuilder.ToString());

            ((HttpWebRequest)webRequest).AllowWriteStreamBuffering = false;
            webRequest.Method = method;
            HeaderList headerList = new HeaderList(protoHeaders);

            headerList.AddHeaderIfAbsent("x-amz-date", DateTime.UtcNow.ToString("ddd, dd MMM yyyy HH:mm:ss ", CultureInfo.InvariantCulture) + "GMT");
            for (int i = 0; i < headerList.Count; i++)
            {
                string a           = headerList.Keys[i];
                string contentType = headerList.Values[i];
                if (a == "content-type")
                {
                    webRequest.ContentType = contentType;
                }
                else
                {
                    webRequest.Headers.Add(headerList.Keys[i], headerList.Values[i]);
                }
            }
            StringBuilder stringBuilder = new StringBuilder();
            HeaderList    headerList2   = new HeaderList();

            foreach (string current in headerList.Keys)
            {
                string text = current.ToLower();
                if (text == "content-type" || text == "content-md5" || text == "date" || text.StartsWith("x-amz-"))
                {
                    headerList2.Add(text, headerList[current]);
                }
            }
            if (headerList2.ContainsKey("x-amz-date"))
            {
                headerList2["date"] = "";
            }
            if (!headerList2.ContainsKey("content-type"))
            {
                headerList2["content-type"] = "";
            }
            if (!headerList2.ContainsKey("content-md5"))
            {
                headerList2["content-md5"] = "";
            }
            stringBuilder.Append(webRequest.Method);
            stringBuilder.Append("\n");
            for (int j = 0; j < headerList2.Count; j++)
            {
                if (headerList2.Keys[j].StartsWith("x-amz-"))
                {
                    stringBuilder.Append(headerList2.Keys[j]);
                    stringBuilder.Append(":");
                    stringBuilder.Append(headerList2.Values[j].Trim());
                }
                else
                {
                    stringBuilder.Append(headerList2.Values[j]);
                }
                stringBuilder.Append("\n");
            }
            stringBuilder.Append("/");
            stringBuilder.Append(objectPath);
            string   text2    = stringBuilder.ToString();
            Encoding encoding = new UTF8Encoding();
            HMACSHA1 hMACSHA  = new HMACSHA1(encoding.GetBytes(this.secretAccessKey));

            byte[] inArray = hMACSHA.ComputeHash(encoding.GetBytes(text2.ToCharArray()));
            string arg     = Convert.ToBase64String(inArray);

            webRequest.Headers.Add("Authorization", string.Format("AWS {0}:{1}", this.accessKeyId, arg));
            return(webRequest);
        }
Пример #5
0
 public HeaderList(HeaderList prototype) : base(prototype)
 {
 }