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

UploadAsync() public method

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.

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 ( Stream stream, string bucketName, string key, CancellationToken cancellationToken = default(CancellationToken) ) : Task
stream Stream /// The stream to read to obtain the content to upload. ///
bucketName string /// The target Amazon S3 bucket, that is, the name of the bucket to upload the stream to. ///
key string /// The key under which the Amazon S3 object is stored. ///
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(Stream stream, string bucketName, string key, CancellationToken cancellationToken = default(CancellationToken))
        {
            var request = ConstructUploadRequest(stream, bucketName, key);
            return UploadAsync(request, cancellationToken);                    
        }

Same methods

TransferUtility::UploadAsync ( TransferUtilityUploadRequest request, 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