예제 #1
0
      public void Add(Stream data, string key, string contentType)
      {
         //using (ObjectAddRequest objectAddRequest = new ObjectAddRequest(S3Storage.BucketName, key))
         //{
         //   byte[] buffer = new byte[data.Length];

         //   data.Read(buffer, 0, (int)data.Length);

         //   objectAddRequest.LoadStreamWithBytes(buffer, contentType);

         //   using (ObjectAddResponse objectAddResponse = _service.ObjectAdd(objectAddRequest))
         //   { }
         //}

         // The first thing we need to do is check for the presence of a Temporary Redirect.  These occur for a few
         // minutes after an EU bucket is created, while S3 creates the DNS entries.  If we get one, we need to upload
         // the file to the redirect URL
         String redirectUrl = null;
         using (BucketListRequest testRequest = new BucketListRequest(S3Storage.BucketName))
         {
            testRequest.Method = "HEAD";
            using (BucketListResponse testResponse = _service.BucketList(testRequest))
            {
               if (testResponse.StatusCode == System.Net.HttpStatusCode.TemporaryRedirect)
               {
                  redirectUrl = testResponse.Headers["Location"].ToString() + key;
               }
            }
         }

         using (ObjectAddRequest request = new ObjectAddRequest(S3Storage.BucketName, key))
         {
            //request.Headers.Add("x-amz-acl", "public-read-write");
            //request.ContentType = ThreeSharpUtils.ConvertExtensionToMimeType(Path.GetExtension(strKey));
            //request.DataStream = oStream;
            //request.BytesTotal = (request.DataStream).Length;
            //request.Timeout = iTimeout;

            byte[] buffer = new byte[data.Length];
            data.Read(buffer, 0, (int)data.Length);
            request.LoadStreamWithBytes(buffer, contentType);

            if (redirectUrl != null)
            {
               request.RedirectUrl = redirectUrl;
            }

            using (ObjectAddResponse response = _service.ObjectAdd(request))
            { }
         }
      }
예제 #2
0
      public void Add(Stream data, string key, string contentType)
      {
         using (ObjectAddRequest objectAddRequest = new ObjectAddRequest(S3Storage.BucketName, key))
         {
            byte[] buffer = new byte[data.Length];

            data.Read(buffer, 0, (int)data.Length);

            objectAddRequest.LoadStreamWithBytes(buffer, contentType);

            using (ObjectAddResponse objectAddResponse = _service.ObjectAdd(objectAddRequest))
            { }
         }
      }