阅读背景:

为什么AWS S3这么慢? (迅速)

来源:互联网 

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:

我正在使用Amazon S3在iOS应用程序上使用swift存储用户帐户的个人资料图片。我能够从S3获取我想要的图片,但是他们需要很长时间才能加载。我不知道为什么会这样。这就是S3的工作方式,还是有更好的方法来做事?这是我下载图片的代码:

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!

任何帮助,将不胜感激!

2 个解决方案

#1


2  

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.

检查返回块中正在运行的队列。如果它不是主队列,设置UIImageView的image属性可能需要很长时间才能“注意”并更新。通过将dispatch_async()内的图像分配行放入主线程来测试这一点。

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

如果这没有帮助,请运行Charles并查看S3返回图像所需的时间。

#2


0  

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.

根据您创建的存储区域和访问位置,下载速度可能会有所不同。在AWS S3中创建存储桶时,请务必选择地理位置接近您所在位置的区域。

This image taken from amazon s3 documentation

这张照片取自亚马逊s3文件

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

您可以在以下链接中引用Amazon s3文档,以了解存储区域。

Thanks!


分享到: