Swift - AWS S3 Upload Image from Photo Library and download it

后端 未结 3 1888
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-15 10:41

I\'ve looked many amazon docs but didn\'t find enough information to upload and download images to S3 using Swift.
How can I do that?

3条回答
  •  萌比男神i
    2020-12-15 11:31

    If all you want is to download the image, this is a much more concise and correct way to do it:

    func downloadImage(bucketName: String, fileName: String, completion: (image: UIImage?, error: NSError?) -> Void) {
        let transferUtility = AWSS3TransferUtility.defaultS3TransferUtility()
    
        transferUtility.downloadDataFromBucket(bucketName, key: fileName, expression: nil) { (task, url, data, error) in
            var resultImage: UIImage?
    
            if let data = data {
                resultImage = UIImage(data: data)
            }
    
            completion(image: resultImage, error: error)
        }
    }
    

提交回复
热议问题