0

So currently I am using this method (in swift) below to get images from my S3 bucket, which works good:

static var completionHandler: AWSS3TransferUtilityDownloadCompletionHandlerBlock?
static var MY_BUCKET = "BUCKET_NAME"

let transferUtility = AWSS3TransferUtility.default()

class func downloadFromS3(key: String, completion: @escaping (_ image: UIImage?, _ error: Error?)-> Void){

    let credentialsProvider = AWSCognitoCredentialsProvider(regionType:.USEast1,identityPoolId:POOL_ID)
    let configuration = AWSServiceConfiguration(region:.USEast1, credentialsProvider:credentialsProvider)

    AWSServiceManager.default().defaultServiceConfiguration = configuration
    let transferUtility = AWSS3TransferUtility.default()
    let expression = AWSS3TransferUtilityDownloadExpression()
    transferUtility.downloadData(fromBucket: MY_BUCKET, key: key, expression: expression) { (task, url, data, error) in
        var resultImage: UIImage?
        if let data = data {
            resultImage = UIImage(data: data)
        }
        completion(resultImage, error)
    }

}

the only problem is that it takes about 5 to 10 seconds to get the image. is there a faster method of getting the images? In Android, there is the Glide library which works perfectly. Is there a library as functional as that in iOS?

Aria
  • 389
  • 3
  • 7
  • 25
  • Not familiar with amazon-web-services, but if you have access to a url for the image you can download it in bytes and rebuild it in your app. Can't imagine it being quicker than that and you wouldn't need any library, just a bare url string to access the image. If you do let me know and I'll help you with that, otherwise it would not be a solution for you. – Alex Ioja-Yang Aug 22 '17 at 15:04
  • @AlexIoja-Yang how does that work? – Aria Aug 22 '17 at 15:06
  • 1
    I just used [this](https://stackoverflow.com/a/27517280/5237289) and it brings it in half the time! – Aria Aug 22 '17 at 15:20
  • That's the way in that link. Just need to make sure you have a clean image url, as if that url returns even just a title or html tag, it will probably crash or create a weird looking image. You could check on one or two examples and just do print(String(data: data, encoding: .utf8)) to visually check there's nothing else at the start/end of your base64encoded string. – Alex Ioja-Yang Aug 22 '17 at 15:35
  • Thanks for your help! @AlexIoja-Yang – Aria Aug 22 '17 at 15:37

0 Answers0