Amazon.S3.Transfer.TransferUtility.UploadAsync C# (CSharp) Method

UploadAsync() public method

Uploads the file or stream specified by the request. To track the progress of the upload, add an event listener to the request's UploadProgressEvent. 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.

If you are uploading large files, TransferUtility will use multipart upload to fulfill the request. If a multipart upload is interrupted, TransferUtility will attempt to abort the multipart upload. Under certain circumstances (network outage, power failure, etc.), TransferUtility will not be able to abort the multipart upload. In this case, in order to stop getting charged for the storage of uploaded parts, you should manually invoke TransferUtility.AbortMultipartUploadsAsync() to abort the incomplete multipart uploads.

public UploadAsync ( TransferUtilityUploadRequest request, CancellationToken cancellationToken = default(CancellationToken) ) : Task
request TransferUtilityUploadRequest /// Contains all the parameters required to upload to Amazon S3. ///
cancellationToken System.Threading.CancellationToken /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. ///
return Task
        public Task UploadAsync(TransferUtilityUploadRequest request, CancellationToken cancellationToken = default(CancellationToken))
        {
            var command = GetUploadCommand(request, null);
            return command.ExecuteAsync(cancellationToken);
        }
        #endregion

Same methods

TransferUtility::UploadAsync ( Stream stream, string bucketName, string key, CancellationToken cancellationToken = default(CancellationToken) ) : Task
TransferUtility::UploadAsync ( string filePath, string bucketName, CancellationToken cancellationToken = default(CancellationToken) ) : Task
TransferUtility::UploadAsync ( string filePath, string bucketName, string key, CancellationToken cancellationToken = default(CancellationToken) ) : Task

Usage Example

 public async Task UploadFile(string name,IStorageFile storageFile)
 {            
     var s3Client = new AmazonS3Client(credentials, RegionEndpoint.USEast1);
     var transferUtilityConfig = new TransferUtilityConfig
     {                
         ConcurrentServiceRequests = 5,                
         MinSizeBeforePartUpload = 20 * MB_SIZE,
     };
     try
     {
         using (var transferUtility = new TransferUtility(s3Client, transferUtilityConfig))
         {
             var uploadRequest = new TransferUtilityUploadRequest
             {
                 BucketName = ExistingBucketName,
                 Key = name,
                 StorageFile = storageFile,
                 // Set size of each part for multipart upload to 10 MB
                 PartSize = 10 * MB_SIZE
             };
             uploadRequest.UploadProgressEvent += OnUploadProgressEvent;
             await transferUtility.UploadAsync(uploadRequest);
         }
     }
     catch (AmazonServiceException ex)
     {
       //  oResponse.OK = false;
      //   oResponse.Message = "Network Error when connecting to AWS: " + ex.Message;
     }
 }
All Usage Examples Of Amazon.S3.Transfer.TransferUtility::UploadAsync