Forum Xamarin.Forms

Download method with AWS S3 in Xamarin Forms

kztnedakztneda Member ✭✭

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?

    using (_clienteS3 = new AmazonS3Client("USER", "PASS", RegionEndpoint.USWest2))
                {
                    try
                    {    
                        var fileCopyName = Path.Combine(Android.OS.Environment.ExternalStorageDirectory.AbsolutePath, Android.OS.Environment.DirectoryDownloads);

                        TransferUtilityDownloadRequest request = new TransferUtilityDownloadRequest()
                        {
                            BucketName = "BUKET",
                            Key = "FILE.png",
                            FilePath = fileCopyName
                        };

                        TransferUtility transferUtility = new TransferUtility(_clienteS3);

                        await transferUtility.DownloadAsync(request).ConfigureAwait(false); // here the app breaks-out and throws the exception before it closes (the app)
                    }
                    catch (Exception e) { } //doesn't catch de exception
                }
            }

Answers

  • JohnHardmanJohnHardman GBUniversity admin

    @kztneda - What does the StackTrace of the ArgumentOutOfRangeException contain? What does the Message of the ArgumentOutOfRangeException contain?

  • kztnedakztneda Member ✭✭

    @JohnHardman it says:

    "System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index"

  • JohnHardmanJohnHardman GBUniversity admin

    @kztneda - And the stack trace?

    Also, you've raised this same question on another thread. Probably best to continue there. See https://forums.xamarin.com/discussion/comment/338226/#Comment_338226

    Also, to investigate, have you tried (a) specifying a cancellation token, and (b) not specifying a FilePath?

  • kztnedakztneda Member ✭✭
    edited July 2018

    @JohnHardman i tried with the cancellation token, but if I don't specify the FilePath where is the object been saved?

  • JohnHardmanJohnHardman GBUniversity admin

    @kztneda said:
    @JohnHardman i tried with the cancellation token, but if I don't specify the FilePath where is the object been saved?

    Trying to work out why you are getting an exception rather than worrying about where the file is saved. One step at a time during debugging.

    You'll notice that the apparently working code in the post at https://forums.xamarin.com/discussion/comment/282776/#Comment_282776 does not specify a FilePath.

    Also, still interested to see the stack trace from the exception to confirm that the exception is thrown where you think it is.

Sign In or Register to comment.