I have a UWP app that Upload a file to an S3 Bucket using the AWS SDK for .NET (high-level API) that is TransferUtility.
This API works very well when I am uploading small size recording files but when I upload larger files the file does not seem to be uploaded and it throws following errors:
An error occurred while sending the request. // in some tests
A task was canceled.
To fix this error, I referred multiple resources from the internet but could not get the solution. I also tried adding different parameters to the TransferUtilityUploadRequest i.e PartSize to determine the size of the multipart segment, added TransferUtilityConfig as an additional parameter to transferUtility, Configured various RegionEndPoints used while sending upload request. Adding these changes did not make any difference while uploading large files to s3 bucket.
Below is the code snippet I am using
int MB_SIZE = (int)Math.Pow(2, 20);
var s3Client = new AmazonS3Client(objUploadRecording.AccessKeyId, objUploadRecording.SecretAccessKey,objUploadRecording.Token, region);
var transferUtilityConfig = new TransferUtilityConfig
{
// Use 5 concurrent requests.
ConcurrentServiceRequests = 5,
// Use multipart upload for file size greater 1 MB.
MinSizeBeforePartUpload = 1 * MB_SIZE,
};
using (var transferUtility = new TransferUtility(s3Client, transferUtilityConfig))
{
var uploadRequest = new TransferUtilityUploadRequest
{
BucketName = objUploadRecording.BucketName,
Key = objUploadRecording.S3Filename,
FilePath = objUploadRecording.FilePath,
// Set size of each part for multipart upload to 1 MB
PartSize = 1 * MB_SIZE
};
uploadRequest.UploadProgressEvent += OnUploadProgressEvent;
CancellationToken cancellationToken = default(CancellationToken);
try
{
await transferUtility.UploadAsync(uploadRequest, ancellationToken);
}
catch (Exception ex)
{
LoggingServices.Instance.WriteLine<RecordingListPage>("AWS Upload
Error: " + ex.Message.ToString(), MetroLog.LogLevel.Error);
}
Can anyone please guide me where I am doing mistake or what additional parameters I will have to add here to make this work?