private TransferUtilityUploadRequest CreateUploadRequest(UploadSettings settings) { TransferUtilityUploadRequest request = new TransferUtilityUploadRequest(); request.BucketName = settings.BucketName; request.ServerSideEncryptionCustomerProvidedKey = settings.EncryptionKey; request.ServerSideEncryptionCustomerProvidedKeyMD5 = settings.EncryptionKeyMD5; request.ServerSideEncryptionCustomerMethod = settings.EncryptionMethod; if (!String.IsNullOrEmpty(settings.EncryptionKey)) { request.ServerSideEncryptionCustomerMethod = ServerSideEncryptionCustomerMethod.AES256; } request.CannedACL = settings.CannedACL; if (settings.Headers != null) { foreach (string key in settings.Headers.Keys) { request.Headers[key] = settings.Headers[key]; } } return(request); }
/// <summary> /// Uploads the specified file. For large uploads, the file will be divided and uploaded in parts /// using Amazon S3's multipart API. The parts will be reassembled as one object in Amazon S3. /// </summary> /// <param name="filePath">The file path of the file to upload.</param> /// <param name="key">The key under which the Amazon S3 object is stored.</param> /// <param name="settings">The <see cref="UploadSettings"/> required to upload to Amazon S3.</param> public void Upload(FilePath filePath, string key, UploadSettings settings) { TransferUtility utility = this.GetUtility(settings); TransferUtilityUploadRequest request = this.CreateUploadRequest(settings); this.SetWorkingDirectory(settings); string fullPath = filePath.MakeAbsolute(settings.WorkingDirectory).FullPath; request.FilePath = fullPath; request.Key = key; //Set ContentType if (settings.GenerateContentType && String.IsNullOrEmpty(request.Headers.ContentType)) { request.Headers.ContentType = new Mime().Lookup(filePath.GetFilename().FullPath); } //Set ETag if (settings.GenerateETag && String.IsNullOrEmpty(request.Headers["ETag"])) { request.Headers["ETag"] = this.GetHash(_FileSystem.GetFile(fullPath)); } request.UploadProgressEvent += new EventHandler <UploadProgressArgs>(UploadProgressEvent); _Log.Verbose("Uploading file {0} to bucket {1}...", key, settings.BucketName); utility.Upload(request); }
/// <summary> /// Generate an ETag based on the hash of the file /// </summary> /// <param name="settings">The sync settings.</param> /// <param name="generateETag">generate ETag.</param> /// <returns>The same <see cref="UploadSettings"/> instance so that multiple calls can be chained.</returns> public static UploadSettings SetGenerateETag(this UploadSettings settings, bool generateETag = true) { if (settings == null) { throw new ArgumentNullException("settings"); } settings.GenerateETag = generateETag; return(settings); }
/// <summary> /// Uploads the contents of the specified stream. For large uploads, the file will be divided and uploaded in parts /// using Amazon S3's multipart API. The parts will be reassembled as one object in Amazon S3. /// </summary> /// <param name="stream">The stream to read to obtain the content to upload.</param> /// <param name="key">The key under which the Amazon S3 object is stored.</param> /// <param name="settings">The <see cref="UploadSettings"/> required to upload to Amazon S3.</param> public void Upload(Stream stream, string key, UploadSettings settings) { TransferUtility utility = this.GetUtility(settings); TransferUtilityUploadRequest request = this.CreateUploadRequest(settings); request.InputStream = stream; request.Key = key; request.UploadProgressEvent += new EventHandler <UploadProgressArgs>(UploadProgressEvent); _Log.Verbose("Uploading file {0} to bucket {1}...", key, settings.BucketName); utility.Upload(request); }
/// <summary> /// Specifies the Storage Class of of an S3 object. Possible values are: ReducedRedundancy: /// provides a 99.99% durability guarantee Standard: provides a 99.999999999% durability guarantee /// </summary> /// <param name="settings">The upload settings.</param> /// <param name="storageClass">The storage class.</param> /// <returns>The same <see cref="UploadSettings"/> instance so that multiple calls can be chained.</returns> public static UploadSettings SetStorageClass(this UploadSettings settings, string storageClass) { if (settings == null) { throw new ArgumentNullException("settings"); } if (string.IsNullOrEmpty(storageClass)) { throw new ArgumentNullException("storageClass"); } settings.StorageClass = S3StorageClass.FindValue(storageClass); return(settings); }
/// <summary> /// Specifies the Storage Class of of an S3 object. Possible values are: ReducedRedundancy: /// provides a 99.99% durability guarantee Standard: provides a 99.999999999% durability guarantee /// </summary> /// <param name="settings">The upload settings.</param> /// <param name="storageClass">The storage class.</param> /// <returns>The same <see cref="UploadSettings"/> instance so that multiple calls can be chained.</returns> public static UploadSettings SetStorageClass(this UploadSettings settings, S3StorageClass storageClass) { if (settings == null) { throw new ArgumentNullException("settings"); } if (storageClass == null) { throw new ArgumentNullException("storageClass"); } settings.StorageClass = storageClass; return(settings); }
/// <summary> /// Specifies the ACL to be used for S3 Buckets or S3 Objects. /// </summary> /// <param name="settings">The upload settings.</param> /// <param name="cannedACL">The canned ACL name.</param> /// <returns>The same <see cref="UploadSettings"/> instance so that multiple calls can be chained.</returns> public static UploadSettings SetCannedACL(this UploadSettings settings, string cannedACL) { if (settings == null) { throw new ArgumentNullException("settings"); } if (string.IsNullOrEmpty(cannedACL)) { throw new ArgumentNullException("cannedACL"); } settings.CannedACL = S3CannedACL.FindValue(cannedACL); return(settings); }
/// <summary> /// Specifies the ACL to be used for S3 Buckets or S3 Objects. /// </summary> /// <param name="settings">The upload settings.</param> /// <param name="cannedACL">The canned ACL.</param> /// <returns>The same <see cref="UploadSettings"/> instance so that multiple calls can be chained.</returns> public static UploadSettings SetCannedACL(this UploadSettings settings, S3CannedACL cannedACL) { if (settings == null) { throw new ArgumentNullException("settings"); } if (cannedACL == null) { throw new ArgumentNullException("cannedACL"); } settings.CannedACL = cannedACL; return(settings); }
/// <summary> /// The id of the AWS Key Management Service key that Amazon S3 should use to encrypt /// and decrypt the object. If a key id is not specified, the default key will be /// </summary> /// <param name="settings">The upload settings.</param> /// <param name="id">The id of the key tp use.</param> /// <returns>The same <see cref="UploadSettings"/> instance so that multiple calls can be chained.</returns> public static UploadSettings SetKeyManagementServiceKeyId(this UploadSettings settings, string id) { if (settings == null) { throw new ArgumentNullException("settings"); } if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException("id"); } settings.KeyManagementServiceKeyId = id; return(settings); }
/// <summary> /// Uploads a collection of files to S3. For large uploads, the file will be divided and uploaded in parts /// using Amazon S3's multipart API. The parts will be reassembled as one object in Amazon S3. /// </summary> /// <param name="paths">The paths to upload.</param> /// <param name="settings">The <see cref="SyncSettings"/> required to upload to Amazon S3.</param> public void Upload(IList <SyncPath> paths, SyncSettings settings) { foreach (SyncPath path in paths) { try { UploadSettings copied = new UploadSettings() { WorkingDirectory = settings.WorkingDirectory, AccessKey = settings.AccessKey, SecretKey = settings.SecretKey, Credentials = settings.Credentials, Region = settings.Region, BucketName = settings.BucketName, EncryptionMethod = settings.EncryptionMethod, EncryptionKey = settings.EncryptionKey, EncryptionKeyMD5 = settings.EncryptionKeyMD5, CannedACL = settings.CannedACL, StorageClass = settings.StorageClass, KeyManagementServiceKeyId = settings.KeyManagementServiceKeyId, Headers = new HeadersCollection(), GenerateContentType = settings.GenerateContentType, GenerateETag = settings.GenerateETag }; if (!String.IsNullOrEmpty(path.ETag)) { copied.Headers["ETag"] = path.ETag; } this.Upload(path.Path, path.Key, copied); } catch (Exception ex) { _Log.Error(ex.Message); } } }
/// <summary> /// Uploads the contents of the specified stream. For large uploads, the file will be divided and uploaded in parts /// using Amazon S3's multipart API. The parts will be reassembled as one object in Amazon S3. /// </summary> /// <param name="stream">The stream to read to obtain the content to upload.</param> /// <param name="key">The key under which the Amazon S3 object is stored.</param> /// <param name="settings">The <see cref="UploadSettings"/> required to upload to Amazon S3.</param> public void Upload(Stream stream, string key, UploadSettings settings) { TransferUtility utility = this.GetUtility(settings); TransferUtilityUploadRequest request = this.CreateUploadRequest(settings); request.InputStream = stream; request.Key = key; request.UploadProgressEvent += new EventHandler<UploadProgressArgs>(UploadProgressEvent); _Log.Verbose("Uploading file {0} to bucket {1}...", key, settings.BucketName); utility.Upload(request); }
/// <summary> /// Uploads the specified file. For large uploads, the file will be divided and uploaded in parts /// using Amazon S3's multipart API. The parts will be reassembled as one object in Amazon S3. /// </summary> /// <param name="filePath">The file path of the file to upload.</param> /// <param name="key">The key under which the Amazon S3 object is stored.</param> /// <param name="settings">The <see cref="UploadSettings"/> required to upload to Amazon S3.</param> public void Upload(FilePath filePath, string key, UploadSettings settings) { TransferUtility utility = this.GetUtility(settings); TransferUtilityUploadRequest request = this.CreateUploadRequest(settings); this.SetWorkingDirectory(settings); string fullPath = filePath.MakeAbsolute(settings.WorkingDirectory).FullPath; request.FilePath = fullPath; request.Key = key; //Set ContentType if (settings.GenerateContentType && String.IsNullOrEmpty(request.Headers.ContentType)) { request.Headers.ContentType = new Mime().Lookup(filePath.GetFilename().FullPath); } //Set Hash Tag string hash = ""; if (!String.IsNullOrEmpty(request.Headers["ETag"])) { hash = request.Headers["ETag"]; } else if (settings.GenerateETag || settings.GenerateHashTag) { hash = this.GetHash(_FileSystem.GetFile(fullPath)); request.Headers["ETag"] = hash; } if (settings.GenerateHashTag) { request.Metadata.Add("HashTag", hash); } request.UploadProgressEvent += new EventHandler<UploadProgressArgs>(UploadProgressEvent); _Log.Verbose("Uploading file {0} to bucket {1}...", key, settings.BucketName); utility.Upload(request); }
public static void S3Upload(this ICakeContext context, Stream stream, string key, UploadSettings settings) { context.CreateManager().Upload(stream, key, settings); }
public static void S3Upload(this ICakeContext context, FilePath filePath, string key, UploadSettings settings) { context.CreateManager().Upload(filePath, key, settings); }
private TransferUtilityUploadRequest CreateUploadRequest(UploadSettings settings) { TransferUtilityUploadRequest request = new TransferUtilityUploadRequest(); request.BucketName = settings.BucketName; request.ServerSideEncryptionCustomerProvidedKey = settings.EncryptionKey; request.ServerSideEncryptionCustomerProvidedKeyMD5 = settings.EncryptionKeyMD5; request.ServerSideEncryptionCustomerMethod = settings.EncryptionMethod; if (!String.IsNullOrEmpty(settings.EncryptionKey)) { request.ServerSideEncryptionCustomerMethod = ServerSideEncryptionCustomerMethod.AES256; } request.CannedACL = settings.CannedACL; if (settings.Headers != null) { foreach (string key in settings.Headers.Keys) { request.Headers[key] = settings.Headers[key]; } } return request; }
public static async Task S3Upload(this ICakeContext context, Stream stream, string key, UploadSettings settings) { await context.CreateManager().Upload(stream, key, settings); }
/// <summary> /// Uploads a collection of files to S3. For large uploads, the file will be divided and uploaded in parts /// using Amazon S3's multipart API. The parts will be reassembled as one object in Amazon S3. /// </summary> /// <param name="paths">The paths to upload.</param> /// <param name="settings">The <see cref="SyncSettings"/> required to upload to Amazon S3.</param> public void Upload(IList<SyncPath> paths, SyncSettings settings) { foreach(SyncPath path in paths) { try { UploadSettings copied = new UploadSettings() { WorkingDirectory = settings.WorkingDirectory, AccessKey = settings.AccessKey, SecretKey = settings.SecretKey, Credentials = settings.Credentials, Region = settings.Region, BucketName = settings.BucketName, EncryptionMethod = settings.EncryptionMethod, EncryptionKey = settings.EncryptionKey, EncryptionKeyMD5 = settings.EncryptionKeyMD5, CannedACL = settings.CannedACL, StorageClass = settings.StorageClass, KeyManagementServiceKeyId = settings.KeyManagementServiceKeyId, Headers = new HeadersCollection(), GenerateContentType = settings.GenerateContentType, GenerateETag = settings.GenerateETag, GenerateHashTag = settings.GenerateHashTag }; if (!String.IsNullOrEmpty(path.ETag)) { copied.Headers["ETag"] = path.ETag; } this.Upload(path.Path, path.Key, copied); } catch (Exception ex) { _Log.Error(ex.Message); } } }