Hi everyone, i'm testing the Amazon Web Services with S3 cloud and trying to make a simple download test from cloud, but i'm stuck with the code and i need a little push up into the right direction, i try to following this two guides from the AWS docs:
docs.aws.amazon.com/mobile/sdkforxamarin/developerguide/getting-started-store-retrieve-s3-transferutility.html
docs.aws.amazon.com/mobile/sdkforxamarin/developerguide/s3-integration-lowlevelapi.html
When i tryit on i only get asyncs methods and i have absolutely no idea how to implement it, here is some of my code:
public class downloadFile : ContentPage { string filePath = ""; string bucketName = "***"; string key = "test.jpg"; public downloadFile() { CognitoAWSCredentials credentials = new CognitoAWSCredentials( "us-east-1:*****", RegionEndpoint.USEast1 ); var config = new TransferUtilityConfig(); var s3Client = new AmazonS3Client(credentials, RegionEndpoint.USEast1); var transferUtility = new TransferUtility(s3Client, config); TransferUtilityDownloadRequest request = new TransferUtilityDownloadRequest(); request.BucketName = bucketName; request.Key = key; transferUtility.DownloadAsync ??????? // Please help me here } }
try
{
TransferUtilityDownloadRequest request = new TransferUtilityDownloadRequest();
request.BucketName = "yourS3path";
request.Key = "download.jpg";
TransferUtility transferUtility = new TransferUtility(client); request.WriteObjectProgressEvent += WriteFileProgress; System.Threading.CancellationToken cancellationToken = new System.Threading.CancellationToken(); await transferUtility.DownloadAsync(request, cancellationToken); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("=====ERROR ========"); }
private void WriteFileProgress(object sender, WriteObjectProgressArgs args)
{
// show progress
System.Diagnostics.Debug.WriteLine("=======UpdateFileProgress=======");
}
Answers
try
{
TransferUtilityDownloadRequest request = new TransferUtilityDownloadRequest();
request.BucketName = "yourS3path";
request.Key = "download.jpg";
private void WriteFileProgress(object sender, WriteObjectProgressArgs args)
{
// show progress
System.Diagnostics.Debug.WriteLine("=======UpdateFileProgress=======");
}
How to find downloaded file in iOS. Do you have any sample.?
Hi, I'm actually in the same problem but when I try to download a file I get "System.ArgumentOutOfRangeException" so the app literally breaks out even when I use try-catch. Does any-one know what is happen?
Here is my code:
@kztneda did you try to wrap the using(...) with the try/catch instead of using it inside ?
Also looks like you don't set your cognito credentials.
are the cognito credentials needed even when the s3 client is logged in?
yep, I tried it.
I don't know what else can I do to get an object