JFDeveloper
JFDeveloper

Reputation: 65

Why is AWS S3 so slow? (Swift)

I am using Amazon S3 to store profile pictures for user accounts on an iOS app using swift.. I am able to get the pictures I want from S3, but it takes a very long time for them to load. I don't know why this is happening. Is that just how S3 works, or is there a better way to do things? This is my code for downloading the picture:

let downloadingFilePath1 = NSTemporaryDirectory().stringByAppendingPathComponent("temp-download")
        let downloadingFileURL1 = NSURL(fileURLWithPath: downloadingFilePath1)
        let transferManager = AWSS3TransferManager.defaultS3TransferManager()
        let readRequest1 : AWSS3TransferManagerDownloadRequest = AWSS3TransferManagerDownloadRequest()
        readRequest1.bucket = "groopapictures"
        readRequest1.key =  self.searchTextField.text
        readRequest1.downloadingFileURL = downloadingFileURL1

        transferManager.download(readRequest1).continueWithBlock { (task) -> AnyObject! in
            println(task.error)
            if task.error == nil {
                self.ppImageView.hidden = false
                println("Fetched image")
                self.ppImageView.image = UIImage(contentsOfFile: downloadingFilePath1)

            }
            return nil
        }

Any help would be appreciated!

Upvotes: 5

Views: 832

Answers (2)

Karthick Selvaraj
Karthick Selvaraj

Reputation: 2505

The downloading speed may get vary based on your bucket created region and your accessing location. Make sure to choose the region which is geographically near to your location while creating the bucket in AWS S3.

This image taken from amazon s3 documentation

You can refer Amazon s3 documentation in following link to get idea about bucket region.

Thanks!

Upvotes: 1

Joshua Sullivan
Joshua Sullivan

Reputation: 1139

Check which queue you're running on in your return block. If it's not the main queue, setting the image property of a UIImageView can take a long time to be "noticed" and updated. Test this by putting the image assignment line inside a dispatch_async() to the main thread.

If that doesn't help, run Charles and see how long S3 is taking to return the image.

Upvotes: 3

Related Questions