所以目前我在下面使用这个方法(在swift中)从我的S3存储桶中获取图像,这很好用:
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)
}
}
唯一的问题是获取图像大约需要5到10秒。是否有更快的方法来获取图像?在Android中,有一个完美的Glide库。是否有像iOS中那样功能的库?