iosswiftamazon-s3awss3transfermanager

Error downloading from S3 bucket on IOS.


I'm having a hard time trying to Download a specific file I've uploaded in my S3 Bucket.

I created a bucket called "Photos" and uploaded the file named "test.png"

After setting my CredentialProvider in my AppDelegate I tried to make a download of that file with the following code:

    let transferManager = AWSS3TransferManager.defaultS3TransferManager()

    let downloadingFilePath = NSTemporaryDirectory().stringByAppendingString("test.png")
    let downloadingFileUrl = NSURL(fileURLWithPath: downloadingFilePath)
    let downloadRequest = AWSS3TransferManagerDownloadRequest()
    downloadRequest.bucket = "photos"
    downloadRequest.key = "test.png"
    downloadRequest.downloadingFileURL = downloadingFileUrl
    transferManager.download(downloadRequest).continueWithExecutor(AWSExecutor.mainThreadExecutor(), withBlock: { (AWSTask) -> AnyObject! in

        //Handle errors
        if AWSTask.error != nil
        {

            print("Error downloading: \(AWSTask.error)")

            // Retrive information important for later downloading
        }
        else
        {
            print("Download succesful..")
            var uploadResult: AnyObject! = AWSTask.result
            print("Upload result: \(uploadResult)")

            let downloadOutput = AWSTask.result as! AWSS3TransferManagerDownloadOutput                

        }
        return nil

    })

But it keeps giving me the error: "The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint"

I tried to change my downloaderRequest.bucket to the endpoint I found in my bucket properties . downloaderRequest.bucket = "photos.s3-website-sa-east-1.amazonaws.com"

But now it says "The specified bucket does not exist, Code=NoSuchBucket"

Any ideas of what Ive be doing wrong? thanks.


Solution

  • I finally figure it out. So the problem here is that I created my bucket in a South American region and Amazon couldn't find it. Even thought when I click in my Amazon region it tell me that "S3 does not require region selection." You need to create it in the "US Standard".