在Xamarin中从AWS S3加载图像

时间:2017-10-12 18:45:15

标签: image amazon-web-services xamarin mobile amazon-s3

我正在尝试从aws S3存储中加载图片,但运行此代码没有任何反应:

//AWS S3
var loggingConfig = AWSConfigs.LoggingConfig;
loggingConfig.LogMetrics = true;
loggingConfig.LogResponses = ResponseLoggingOption.Always;
loggingConfig.LogMetricsFormat = LogMetricsFormatOption.JSON;
loggingConfig.LogTo = LoggingOptions.SystemDiagnostics;
AWSConfigs.AWSRegion = "us-east-1";
AWSConfigsS3.UseSignatureVersion4 = true;

CognitoAWSCredentials mycredentials = 
    new CognitoAWSCredentials("eu-west-1:a1e69edc-7ee4-4c67-90de-4b7ae67efbb6", RegionEndpoint.USEast1);
var s3Client = new AmazonS3Client(mycredentials, RegionEndpoint.USEast1);
var transferUtility = new TransferUtility(s3Client);


TransferUtilityDownloadRequest downreq = new TransferUtilityDownloadRequest();
downreq.FilePath = Environment.SpecialFolder.ApplicationData.ToString() + "Add.png";
downreq.BucketName = "crejopod";
downreq.Key = "Add.png";
CancellationToken token = new CancellationToken(true);
transferUtility.DownloadAsync(downreq, token);

//show the image
dayImage.Source = Environment.SpecialFolder.ApplicationData.ToString() + "Add.png";

因为我使用的是awssdk的Version3,所以我必须使用DownloadAsync()函数。

0 个答案:

没有答案