在Xamarin iOS中从AWS S3下载文件通常会挂起

时间:2018-10-19 04:43:37

标签: c# file amazon-s3 download xamarin.ios

我正在尝试在Xamarin iOS iPad App中下载大小为85MB的XML文件。 有时下载成功完成,但其他时候下载挂起之间没有任何错误。进度停止。

AWS SDK版本:

AWSSDK.S3 3.3.20.4

AWSSDK.Core 3.3.24.8

我尝试了两种方法1- TransferUtility 2- GetObject。 这是我的代码:

            var  clientRequest = new AmazonS3Client(AWSAccessKey,
                                    AWSSecretKey,
                                        Amazon.RegionEndpoint.USEast1);
            try
            {
                GetObjectRequest request = new GetObjectRequest
                {
                    BucketName = AWSBucketName,
                    Key = Path + "File1.xml"
                };
                using (GetObjectResponse response = await clientRequest.GetObjectAsync(request))
                {
                 response.WriteObjectProgressEvent += displayDownloadProgress;
                 await response.WriteResponseStreamToFileAsync(destPath, false);                        
                }
            }
            catch (AmazonS3Exception e)
            {
                Console.WriteLine("Error encountered ***. Message:'{0}' when writing an object", e.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine("Unknown encountered on server. Message:'{0}' when writing an object", e.Message);
            }

我一一尝试了这两种方法。

            var utility = new TransferUtility(cas.AWSAccessKey,
                                    cas.AWSSecretKey,
                                    Amazon.RegionEndpoint.USEast1);

            TransferUtilityDownloadRequest dr = new TransferUtilityDownloadRequest();
            dr.BucketName = AWSBucketName;
            dr.Key = Path + "File1.xml";
            dr.FilePath = destPath;
            dr.WriteObjectProgressEvent += displayDownloadProgress;
            await utility.DownloadAsync(dr);



            public void displayDownloadProgress(object sender, WriteObjectProgressArgs args)
            {
                Debug.WriteLine("Download Progress: " + (args.PercentDone));

                InvokeOnMainThread(() =>
                {
                    BTProgressHUD.ShowContinuousProgress("Download Progress: " + args.PercentDone.ToString() + "%", ProgressHUD.MaskType.Gradient);
                });

                if (args.PercentDone >= 100)
                {
                    BTProgressHUD.Dismiss();
                }
            }

0 个答案:

没有答案