/* This function is to upload data to S3. */ public static int UploadDataToS3(string NameOfThebucket, string DirectoryPath, string RegionOftheBucket) { if (DirectoryPath.Contains(".") == true) { RegionOftheBucket = RegionOftheBucket.ToLower(); try { TransferUtility directoryTransferUtility = new TransferUtility(AccessKey, SecretKey, Amazon.RegionEndpoint.GetBySystemName(ClientRegion(RegionOftheBucket))); AmazonS3Client client = new AmazonS3Client(AccessKey, SecretKey, Amazon.RegionEndpoint.GetBySystemName(ClientRegion(RegionOftheBucket))); int len = DirectoryPath.Length; int temp = DirectoryPath.LastIndexOf("\\"); string KeyName = DirectoryPath.Substring(temp + 1, len - temp -1); PutObjectRequest Request = new PutObjectRequest { BucketName = NameOfThebucket, Key = KeyName, FilePath = DirectoryPath, ContentType = "text/plain" }; client.PutObject(Request); Console.WriteLine("Transfer Complete"); return 0; } catch(Exception e) { Console.WriteLine("ERROR MESSAGE : " + e.Message); } } try { TransferUtility directoryTransferUtility = new TransferUtility(AccessKey, SecretKey, Amazon.RegionEndpoint.GetBySystemName(ClientRegion(RegionOftheBucket))); AmazonS3Client client = new AmazonS3Client(AccessKey, SecretKey, Amazon.RegionEndpoint.GetBySystemName(ClientRegion(RegionOftheBucket))); directoryTransferUtility.UploadDirectory(DirectoryPath, NameOfThebucket); directoryTransferUtility.UploadDirectory(DirectoryPath, NameOfThebucket, "*.*", SearchOption.AllDirectories); TransferUtilityUploadDirectoryRequest request = new TransferUtilityUploadDirectoryRequest { BucketName = NameOfThebucket, Directory = DirectoryPath, SearchOption = SearchOption.AllDirectories, SearchPattern = "*.*" }; directoryTransferUtility.UploadDirectory(request); Console.WriteLine("Transfer Complete"); return 0; } catch (AmazonS3Exception e) { Console.WriteLine("There is Some Problem"); Console.WriteLine(e.Message, e.InnerException); } return 0; }
public void Deploy(List <Argument> args) { assetsLocalPath = ArgumentHelper.Find("-AssetsLocalPath", args); bucketPath = ArgumentHelper.Find("-BucketPath", args); awsAccessKey = ArgumentHelper.Find("-AwsAccessKey", args); awsSecretKey = ArgumentHelper.Find("-AwsSecretKey", args); awsRegion = ArgumentHelper.Find("-AwsRegion", args); if (string.IsNullOrEmpty(assetsLocalPath) || string.IsNullOrEmpty(bucketPath) || string.IsNullOrEmpty(awsAccessKey) || string.IsNullOrEmpty(awsSecretKey) || string.IsNullOrEmpty(awsRegion)) { throw new Exception("The parameres are not defined. -AssetsLocalPath,-BucketPath,-AwsAccessKey,-AwsSecretKey,-AwsRegion"); } var s3Client = new AmazonS3Client(new BasicAWSCredentials(awsAccessKey, awsSecretKey), RegionEndpoint.GetBySystemName(awsRegion)); TransferUtility directoryTransferUtility = new TransferUtility(s3Client); directoryTransferUtility.UploadDirectory(new TransferUtilityUploadDirectoryRequest() { BucketName = bucketPath, Directory = assetsLocalPath, UploadFilesConcurrently = true, CannedACL = S3CannedACL.PublicRead, SearchOption = SearchOption.AllDirectories }); }
public void UploadDirS3Tranfer(string AccessKey, string SerectKey, string bucketName, string endPoint, string DirectoryPath, EventHandler <UploadDirectoryProgressArgs> UploadProgressEvent = null) { try { using (var client = new AmazonS3Client(AccessKey, SerectKey, RegionEndpointS3.ParseRegion(endPoint))) { var uploadRequest = new TransferUtilityUploadDirectoryRequest { Directory = DirectoryPath, BucketName = bucketName, SearchPattern = "*.zip", SearchOption = System.IO.SearchOption.AllDirectories, KeyPrefix = Guid.NewGuid().ToString(), CannedACL = S3CannedACL.PublicRead }; uploadRequest.UploadDirectoryProgressEvent += UploadProgressEvent; using (var Utility = new TransferUtility(client)) { Utility.UploadDirectory(uploadRequest); } } } catch (AmazonS3Exception ex) { throw new AmazonS3Exception(string.Format("Message {0} Error Code {1} Status Code {2}", ex.Message, ex.ErrorCode, ex.StatusCode)); } }
private static void UploadWeb() { var path = "../../../Web/"; try { var m = Directory.GetFiles(path); Console.WriteLine("Starting Web Upload"); TransferUtility directoryTransferUtility = new TransferUtility(new AmazonS3Client(Amazon.RegionEndpoint.USWest2), new TransferUtilityConfig() { ConcurrentServiceRequests = 50, }); var transferUtilityUploadDirectoryRequest = new TransferUtilityUploadDirectoryRequest() { Directory = path, BucketName = "socialwargames.com", SearchPattern = "*.*", SearchOption = SearchOption.AllDirectories, UploadFilesConcurrently = true, CannedACL = S3CannedACL.PublicRead }; transferUtilityUploadDirectoryRequest.UploadDirectoryProgressEvent += (sender, e) => { Console.WriteLine("Files Uploaded: " + e.NumberOfFilesUploaded); }; directoryTransferUtility.UploadDirectory(transferUtilityUploadDirectoryRequest); Console.WriteLine("Starting Invalidate"); AmazonCloudFrontClient oClient = new AmazonCloudFrontClient(Amazon.RegionEndpoint.USWest2); CreateInvalidationRequest oRequest = new CreateInvalidationRequest(); oRequest.DistributionId = "E34LW6CB5ZCWQU"; oRequest.InvalidationBatch = new InvalidationBatch { CallerReference = DateTime.Now.Ticks.ToString(), Paths = new Paths() { Items = new List <string>() { "/*" }, Quantity = 1 } }; CreateInvalidationResponse oResponse = oClient.CreateInvalidation(oRequest); oClient.Dispose(); Console.WriteLine("Done Web Upload"); } catch (AmazonS3Exception e) { Console.WriteLine(e.Message, e.InnerException); } }
public void UploadDirectory(string directoryToUpload, string uploadFolderKey) { // Delete the directory first in case the directory to upload is a strict subset of the existing contents. DeleteBookData(_bucketName, uploadFolderKey); using (var fileTransferUtility = new TransferUtility(GetAmazonS3(_bucketName))) { fileTransferUtility.UploadDirectory(directoryToUpload, $"{_bucketName}/{uploadFolderKey}", "*.*", System.IO.SearchOption.AllDirectories); } }
private Task UploadDirectoryAsync(string directoryName, long size, DirectoryProgressValidator <UploadDirectoryProgressArgs> progressValidator, bool validate = true, bool concurrent = true) { var directoryPath = Path.Combine(basePath, directoryName); for (int i = 0; i < 5; i++) { var filePath = Path.Combine(Path.Combine(directoryPath, i.ToString()), "file.txt"); //MultipartUploadTests.UtilityMethods.GenerateFile(filePath, (i % 2 == 0) ? size : size / 2); UtilityMethods.GenerateFile(filePath, size); } var config = new TransferUtilityConfig { ConcurrentServiceRequests = 10, }; var transferUtility = new TransferUtility(Client, config); var request = new TransferUtilityUploadDirectoryRequest { BucketName = testBucketName, Directory = directoryPath, KeyPrefix = directoryName, SearchPattern = "*", SearchOption = SearchOption.AllDirectories, }; //if (concurrent) // request.UploadFilesConcurrently = true; if (progressValidator != null) { request.UploadDirectoryProgressEvent += progressValidator.OnProgressEvent; } HashSet <string> files = new HashSet <string>(); request.UploadDirectoryProgressEvent += (s, e) => { files.Add(e.CurrentFile); Console.WriteLine("Progress callback = " + e.ToString()); }; transferUtility.UploadDirectory(request); Assert.Equal(5, files.Count); if (validate) { return(ValidateDirectoryContents(testBucketName, directoryName, directoryPath)); } else { return(Task.FromResult <object>(null)); } }
void UploadDirectory(string directoryName, long size, TransferUtilityTests.DirectoryProgressValidator <UploadDirectoryProgressArgs> progressValidator, bool validate = true) { var directoryPath = Path.Combine(basePath, directoryName); for (int i = 0; i < 5; i++) { var filePath = Path.Combine(Path.Combine(directoryPath, i.ToString()), "file.txt"); UtilityMethods.GenerateFile(filePath, size); } var config = new TransferUtilityConfig { ConcurrentServiceRequests = 10, }; var transferUtility = new TransferUtility(Client, config); var request = new TransferUtilityUploadDirectoryRequest { BucketName = bucketName, Directory = directoryPath, KeyPrefix = directoryName, SearchPattern = "*", SearchOption = SearchOption.AllDirectories, }; if (progressValidator != null) { request.UploadDirectoryProgressEvent += progressValidator.OnProgressEvent; } HashSet <string> files = new HashSet <string>(); request.UploadDirectoryProgressEvent += (s, e) => { files.Add(e.CurrentFile); Console.WriteLine("Progress callback = " + e.ToString()); }; request.UploadDirectoryFileRequestEvent += (s, e) => { var uploadRequest = e.UploadRequest; var key = uploadRequest.Key; keysToValidate.Add(key); SetMetadataAndHeaders(uploadRequest); }; transferUtility.UploadDirectory(request); Assert.AreEqual(5, files.Count); if (validate) { TransferUtilityTests.ValidateDirectoryContents(bucketName, directoryName, directoryPath); } }
void UploadDirectory(long size, TransferUtilityTests.DirectoryProgressValidator <UploadDirectoryProgressArgs> progressValidator, bool validate = true) { var directory = TransferUtilityTests.CreateTestDirectory(size); var directoryPath = directory.FullName; var keyPrefix = directory.Name; var config = new TransferUtilityConfig { ConcurrentServiceRequests = 10, }; var transferUtility = new TransferUtility(Client, config); var request = new TransferUtilityUploadDirectoryRequest { BucketName = bucketName, Directory = directoryPath, KeyPrefix = keyPrefix, SearchPattern = "*", SearchOption = SearchOption.AllDirectories, }; if (progressValidator != null) { request.UploadDirectoryProgressEvent += progressValidator.OnProgressEvent; } HashSet <string> files = new HashSet <string>(); request.UploadDirectoryProgressEvent += (s, e) => { files.Add(e.CurrentFile); Console.WriteLine("Progress callback = " + e.ToString()); }; request.UploadDirectoryFileRequestEvent += (s, e) => { var uploadRequest = e.UploadRequest; var key = uploadRequest.Key; keysToValidate.Add(key); SetMetadataAndHeaders(uploadRequest); }; transferUtility.UploadDirectory(request); Assert.AreEqual(5, files.Count); if (validate) { TransferUtilityTests.ValidateDirectoryContents(Client, bucketName, keyPrefix, directory); } }
DirectoryInfo UploadDirectory(long size, DirectoryProgressValidator <UploadDirectoryProgressArgs> progressValidator, bool validate = true, bool concurrent = true) { var directory = CreateTestDirectory(size); var keyPrefix = directory.Name; var directoryPath = directory.FullName; var config = new TransferUtilityConfig { ConcurrentServiceRequests = 10, }; var transferUtility = new TransferUtility(Client, config); var request = new TransferUtilityUploadDirectoryRequest { BucketName = bucketName, Directory = directoryPath, KeyPrefix = keyPrefix, ContentType = plainTextContentType, SearchPattern = "*", SearchOption = SearchOption.AllDirectories, }; //if (concurrent) // request.UploadFilesConcurrently = true; if (progressValidator != null) { request.UploadDirectoryProgressEvent += progressValidator.OnProgressEvent; } HashSet <string> files = new HashSet <string>(); request.UploadDirectoryProgressEvent += (s, e) => { files.Add(e.CurrentFile); Console.WriteLine("Progress callback = " + e.ToString()); }; transferUtility.UploadDirectory(request); Assert.AreEqual(5, files.Count); if (validate) { ValidateDirectoryContents(Client, bucketName, keyPrefix, directory, plainTextContentType); } return(directory); }
public static int UploadToS3() { string AccessKey = "*** Enter Access Key ***"; string SecretKey = "*** Enter Secret Key ***"; string existingBucketName = "*** Bucket Name ***"; string directoryPath = @"*** Location of the File ***"; string RegionOFTheBucket = " *** Enter the Region of the bucket (Eg: mumbai) *** "; RegionOFTheBucket = RegionOFTheBucket.ToLower(); try { // Here Region of the bucket is Mumbai. Change the region as per your bucket // Amazon Client provides access to S3 TransferUtility directoryTransferUtility = new TransferUtility(); AmazonS3Client client = new AmazonS3Client(AccessKey, SecretKey, Amazon.RegionEndpoint.GetBySystemName(ClientRegion(RegionOFTheBucket))); directoryTransferUtility.UploadDirectory(directoryPath, existingBucketName); directoryTransferUtility.UploadDirectory(directoryPath, existingBucketName, "*.*", SearchOption.AllDirectories); TransferUtilityUploadDirectoryRequest request = new TransferUtilityUploadDirectoryRequest { BucketName = existingBucketName, Directory = directoryPath, SearchOption = SearchOption.AllDirectories, SearchPattern = "*.*" }; directoryTransferUtility.UploadDirectory(request); } catch (AmazonS3Exception e) { Console.WriteLine("There is Some Problem"); Console.WriteLine(e.Message, e.InnerException); } Directory.Delete(directoryPath, true); Directory.CreateDirectory(directoryPath); Console.ReadLine(); }
/// <summary> /// Publish a directory to a S3 bucket, in the folder specified, optionally making it publically readable. /// </summary> public void PublishDirectory(string sourceDirectory, string bucketName, string destinationFolder, bool isPublicRead) { destinationFolder = GetDestinationFolder(destinationFolder); var directoryTransferUtility = new TransferUtility(Client); directoryTransferUtility.UploadDirectory(new TransferUtilityUploadDirectoryRequest { Directory = sourceDirectory, BucketName = bucketName, SearchOption = SearchOption.AllDirectories, KeyPrefix = destinationFolder, CannedACL = isPublicRead ? S3CannedACL.PublicRead : S3CannedACL.Private }); }
public static void TestTransferUtility(IAmazonS3 s3EncryptionClient, IAmazonS3 s3DecryptionClient, string bucketName) { var directory = TransferUtilityTests.CreateTestDirectory(10 * TransferUtilityTests.KILO_SIZE); var keyPrefix = directory.Name; var directoryPath = directory.FullName; using (var transferUtility = new TransferUtility(s3EncryptionClient)) { var uploadRequest = CreateUploadDirRequest(directoryPath, keyPrefix, bucketName); transferUtility.UploadDirectory(uploadRequest); var newDir = TransferUtilityTests.GenerateDirectoryPath(); transferUtility.DownloadDirectory(bucketName, keyPrefix, newDir); TransferUtilityTests.ValidateDirectoryContents(s3DecryptionClient, bucketName, keyPrefix, directory); } }
public void TestUploadDirectoryViaTransferUtility() { var transferConfig = new TransferUtilityConfig { MinSizeBeforePartUpload = 6000000 }; var transfer = new TransferUtility(Client, transferConfig); var directoryKey = UtilityMethods.GenerateName(nameof(ObjectLockConfigurationTests)); var directoryPath = Path.Combine(Path.GetTempPath(), directoryKey); Dictionary <string, int> filesWithSize = new Dictionary <string, int>() { { directoryKey + "_1.txt", 7000000 }, // MultipartUpload { directoryKey + "_2.txt", 2000000 }, // SimpleUpload { directoryKey + "_3.txt", 4000000 }, // SimpleUpload }; // Create directory with files. Directory.CreateDirectory(directoryPath); foreach (var file in filesWithSize) { var filePath = Path.Combine(directoryPath, file.Key); var content = new string('a', file.Value); // Create the file using (StreamWriter writer = File.CreateText(filePath)) { writer.Write(content); } } var uploadDirectoryRequest = new TransferUtilityUploadDirectoryRequest { BucketName = bucketName, Directory = directoryPath, CalculateContentMD5Header = true }; transfer.UploadDirectory(uploadDirectoryRequest); // Verify the files foreach (var file in filesWithSize) { using (var getResponse = Client.GetObject(bucketName, file.Key)) { var getBody = new StreamReader(getResponse.ResponseStream).ReadToEnd(); Assert.AreEqual(new string('a', file.Value), getBody); } } }
/// <summary> /// 那么,bucketName就是HMNUM, dir就是图片跟目录+HMNUM. /// Change1:A bucket is owned by the AWS account that created it. Each AWS account can own up to 100 buckets at a time. /// Bucket ownership is not transferable; however, if a bucket is empty, you can delete it. After a bucket is deleted, /// the name becomes available to reuse, but the name might not be available for you to reuse for various reasons. For /// example, some other account could create a bucket with that name. Note, too, that it might take some time before /// the name can be reused. So if you want to use the same bucket name, don't delete the bucket. /// http://docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html /// 所以,Bucket不应该用HMNUM来创建,而应该由我们指定配置一个!然后再Buket里面创建以HMNUM命名的文件夹。2014年4月9日 /// </summary> /// <param name="dir">本地(绝对路径)文件夹</param> /// <param name="folderName">对应HMNUM,每一个HMNUM在云上当做一个新文件夹存储</param> private void UploadDirectory(string dir, string folderName) { try { //The specified key does not exist. var dbAccess = new DBAccess(); dbAccess.UploadingCloudStatus(folderName, 2); using (var directoryTransferUtility = new TransferUtility(_s3Client)) { var tuudRequest = new TransferUtilityUploadDirectoryRequest { CannedACL = S3CannedACL.PublicRead, Directory = dir, BucketName = _defaultBucketName + "/" + folderName, SearchOption = System.IO.SearchOption.AllDirectories //SearchPattern = "*.JPG" }; directoryTransferUtility.UploadDirectory(tuudRequest); dbAccess.UploadingCloudStatus(folderName, 4); } // Upload a directory. //directoryTransferUtility.UploadDirectory(dir, "media.cms.noblehouse/" + folderName); 这句话会导致图像变成private link,因为没有设置权限..2014年4月10日 } catch (AmazonS3Exception ex) { var dbAccess = new DBAccess(); dbAccess.UploadingCloudStatus(folderName, 3); NBCMSLoggerManager.Error(""); NBCMSLoggerManager.Error(ex.Message); NBCMSLoggerManager.Error(ex.StackTrace); NBCMSLoggerManager.Error(""); } catch (Exception ex) { var dbAccess = new DBAccess(); dbAccess.UploadingCloudStatus(folderName, 3); NBCMSLoggerManager.Error(""); NBCMSLoggerManager.Error(ex.Message); NBCMSLoggerManager.Error(ex.StackTrace); NBCMSLoggerManager.Error(""); } }
public void BlockTransferUtilityUploadDirectoryTest() { var transferUtility = new TransferUtility(RegionEndpoint.USWest2); try { transferUtility.UploadDirectory(new TransferUtilityUploadDirectoryRequest { BucketName = "arn:aws:s3-object-lambda:us-west-2:123456789012:accesspoint/mybanner", Directory = @"c:\foo\bar" }); } catch (AmazonS3Exception e) { var expectedMessage = "UploadDirectory does not support S3 Object Lambda resources"; Assert.AreEqual(expectedMessage, e.Message); } }
public void UploadFolder(String folderPath) { MessageToUser m = new MessageToUser(); Thread startingThread = new Thread(m.UploadToS3); startingThread.Start(); TransferUtilityUploadDirectoryRequest request = new TransferUtilityUploadDirectoryRequest() { BucketName = _bucket, Directory = folderPath, SearchOption = SearchOption.AllDirectories, SearchPattern = "*.zip", KeyPrefix = "mods" }; TransferUtility directorytTransferUtility = new TransferUtility(_client); directorytTransferUtility.UploadDirectory(request); MessageBox.Show("Done uploading files to s3"); }
private void TestUploadDirectory(string bucketName, string keyId) { var directoryName = UtilityMethods.GenerateName("UploadDirectoryTest"); var directoryPath = Path.Combine(basePath, directoryName); for (int i = 0; i < 5; i++) { var filePath = Path.Combine(Path.Combine(directoryPath, i.ToString()), "file.txt"); UtilityMethods.WriteFile(filePath, fileContents); } var config = new TransferUtilityConfig { ConcurrentServiceRequests = 10, }; var transferUtility = new TransferUtility(Client, config); var request = new TransferUtilityUploadDirectoryRequest { BucketName = bucketName, Directory = directoryPath, KeyPrefix = directoryName, SearchPattern = "*", SearchOption = SearchOption.AllDirectories, ServerSideEncryptionMethod = ServerSideEncryptionMethod.AWSKMS, ServerSideEncryptionKeyManagementServiceKeyId = keyId }; HashSet <string> keys = new HashSet <string>(); request.UploadDirectoryFileRequestEvent += (s, e) => { keys.Add(e.UploadRequest.Key); }; transferUtility.UploadDirectory(request); Assert.AreEqual(5, keys.Count); foreach (var key in keys) { VerifyObject(bucketName, key, keyId); } }
/// <summary> /// Upload specified Diretory to S3 bucket /// </summary> /// <param name="uploadDirectory"></param> /// <param name="bucket"></param> /// <returns></returns> public bool SaveAsset(string uploadDirectory, string bucket) { try { TransferUtilityUploadDirectoryRequest request = new TransferUtilityUploadDirectoryRequest { BucketName = bucket, Directory = uploadDirectory, SearchOption = System.IO.SearchOption.AllDirectories, CannedACL = S3CannedACL.PublicRead }; _transferUtility.UploadDirectory(request); return(true); } catch (Exception exception) { Console.WriteLine(exception.InnerException.Message); return(false); } }
public void UploadDirectoty(string bucketName, string directoryPath) { using (var client = GetClient()) { var directoryTransferUtility = new TransferUtility(client); var request = new TransferUtilityUploadDirectoryRequest() { BucketName = bucketName, Directory = directoryPath, SearchOption = SearchOption.AllDirectories, StorageClass = S3StorageClass.Standard, CannedACL = S3CannedACL.PublicRead, UploadFilesConcurrently = true }; request.UploadDirectoryFileRequestEvent += Request_UploadDirectoryFileRequestEvent; request.UploadDirectoryProgressEvent += Request_UploadDirectoryProgressEvent; directoryTransferUtility.UploadDirectory(request); } }
private static void UploadDirAsync(IAmazonS3 s3Client, string dirPath, string bucketName) { try { var dirTransferUtility = new TransferUtility(); var request = new TransferUtilityUploadDirectoryRequest { BucketName = bucketName, Directory = dirPath, SearchOption = SearchOption.AllDirectories, CannedACL = S3CannedACL.PublicRead }; dirTransferUtility.UploadDirectory(request); } catch (AmazonS3Exception e) { Debug.LogError(e.Message); } catch (Exception e) { Debug.LogError(e.Message); } }
/// <summary> /// Uploads a directory to AWS S3 /// </summary> /// <param name="directoryToUpload">The local directory whose contents should be uploaded to S3</param> /// <param name="uploadFolderKey">The key prefix of the S3 objects to create (i.e., which subfolder to upload it to)</param> public void UploadDirectory(string directoryToUpload, string uploadFolderKey) { // Delete the directory first in case the directory to upload is a strict subset of the existing contents. DeleteBookData(_bucketName, uploadFolderKey); using (var transferUtility = new TransferUtility(GetAmazonS3(_bucketName))) { var request = new TransferUtilityUploadDirectoryRequest { Directory = directoryToUpload, BucketName = _bucketName, KeyPrefix = uploadFolderKey, SearchPattern = "*.*", SearchOption = System.IO.SearchOption.AllDirectories, CannedACL = S3CannedACL.PublicRead }; // Set cache control for uploaded items. See https://issues.bloomlibrary.org/youtrack/issue/BL-8198 // and https://forums.aws.amazon.com/thread.jspa?threadID=144559. request.Metadata.Add("Cache-Control", "no-cache"); // Enhance: Could call the BloomDesktop code directly in future if desired. transferUtility.UploadDirectory(request); } }
private CmdletOutput UploadFolderToS3(ExecutorContext context) { var cmdletContext = context as CmdletContext; var request = new TransferUtilityUploadDirectoryRequest { Directory = cmdletContext.Folder, BucketName = cmdletContext.BucketName, KeyPrefix = cmdletContext.KeyPrefix, ContentType = cmdletContext.ContentType }; if (cmdletContext.Recurse) { request.SearchOption = SearchOption.AllDirectories; } else { request.SearchOption = SearchOption.TopDirectoryOnly; } if (!string.IsNullOrEmpty(cmdletContext.SearchPattern)) { request.SearchPattern = cmdletContext.SearchPattern; } if (cmdletContext.CannedACL != null) { request.CannedACL = cmdletContext.CannedACL.Value; } if (cmdletContext.StorageClass != null) { request.StorageClass = cmdletContext.StorageClass.Value; } if (cmdletContext.ServerSideEncryptionMethod != null) { request.ServerSideEncryptionMethod = cmdletContext.ServerSideEncryptionMethod.Value; } if (cmdletContext.ServerSideEncryptionKeyManagementServiceKeyId != null) { request.ServerSideEncryptionKeyManagementServiceKeyId = cmdletContext.ServerSideEncryptionKeyManagementServiceKeyId; } if (cmdletContext.TagSet != null) { request.TagSet = new List <Tag>(cmdletContext.TagSet); } AmazonS3Helper.SetExtraRequestFields(request, cmdletContext); CmdletOutput output; using (var tu = new TransferUtility(Client ?? CreateClient(_CurrentCredentials, _RegionEndpoint))) { Utils.Common.WriteVerboseEndpointMessage(this, Client.Config, "Amazon S3 object upload APIs"); var runner = new ProgressRunner(this); var tracker = new UploadFolderProgressTracker(runner, handler => request.UploadDirectoryProgressEvent += handler, cmdletContext.Folder); output = runner.SafeRun(() => tu.UploadDirectory(request), tracker); WriteVerbose(string.Format("Uploaded {0} object(s) to bucket '{1}' from '{2}' with keyprefix '{3}'", tracker.UploadedCount, cmdletContext.BucketName, cmdletContext.Folder, cmdletContext.OriginalKeyPrefix)); } return(output); }