예제 #1
0
        public static Task Upload(this IS3Repository repository, string bucket, string key, byte[] bytes)
        {
#if PORTABLE
            return(repository.Upload(bucket, key, new MemoryStream(bytes), bytes.Length, null));
#else
            return(repository.Upload(bucket, key, new MemoryStream(bytes), bytes.LongLength, null));
#endif
        }
예제 #2
0
 public static string Upload(this S3 s3, string bucket, Stream stream, long?length)
 {
     bucket = bucket ?? BucketName;
     if (stream == null)
     {
         throw new ArgumentNullException("Stream can't be null.");
     }
     if (string.IsNullOrEmpty(s3.Key))
     {
         s3.Bucket = bucket;
         s3.Key    = Guid.NewGuid().ToString();
     }
     else if (s3.Bucket != bucket)
     {
         throw new ArgumentException("Can't change bucket name");
     }
     s3.cachedContent = null;
     if (length == null)
     {
         var tms = stream as MemoryStream;
         if (tms != null)
         {
             s3.Length = tms.Length;
         }
         else
         {
             try { s3.Length = stream.Length; }
             catch
             {
                 using (var ms = new MemoryStream())
                 {
                     stream.CopyTo(ms);
                     s3.Length   = ms.Length;
                     ms.Position = 0;
                     Repository.Upload(s3.Bucket, s3.Key, stream, s3.Length, s3.Metadata).Wait();
                     return(s3.Key);
                 }
             }
         }
     }
     else
     {
         s3.Length = length.Value;
     }
     Repository.Upload(s3.Bucket, s3.Key, stream, s3.Length, s3.Metadata).Wait();
     return(s3.Key);
 }
예제 #3
0
 public static Task Upload(this IS3Repository repository, string bucket, string key, Stream stream)
 {
     return(repository.Upload(bucket, key, stream, stream.Length, null));
 }