iOS 应用程序:如何使用 kingfisher/sdwebimage 下载 aws s3 图像
iOS app: how to use kingfisher/sdwebimage to download aws s3 image
我想使用 kingfisher 在我的 swiftui 项目中的 collectionview 或列表中显示来自 aws s3 保护文件夹的图像。但是我找不到显示图像的解决方案,因为 aws 需要在请求中包含额外的 headers。我尝试添加备忘单中提到的自定义 header,但没有任何反应。
您可以选择 Kingfisher 用于缓存的密钥。因此,创建一个预签名的 s3 url,然后在加载图像时使用您的 s3 密钥作为缓存,而不是完整的预签名 url.
let getPreSignedURLRequest = AWSS3GetPreSignedURLRequest()
getPreSignedURLRequest.bucket = media.bucket
getPreSignedURLRequest.key = media.key
getPreSignedURLRequest.httpMethod = .GET
getPreSignedURLRequest.expires = Date(timeIntervalSinceNow: 3600) // Change the value of the expires time interval as required
AWSS3PreSignedURLBuilder.default().getPreSignedURL(getPreSignedURLRequest).continueWith { (task:AWSTask<NSURL>) -> Any? in
if let error = task.error as NSError? {
print("Error: \(error)")
return nil
}
if let presignedURL = task.result {
DispatchQueue.main.async {
self.imageView.kf.indicatorType = .activity
let resource = ImageResource(downloadURL: URL(string: presignedURL.absoluteString!)!, cacheKey: media.key)
self.imageView.kf.setImage(with: resource)
}
}
return nil
}
我想使用 kingfisher 在我的 swiftui 项目中的 collectionview 或列表中显示来自 aws s3 保护文件夹的图像。但是我找不到显示图像的解决方案,因为 aws 需要在请求中包含额外的 headers。我尝试添加备忘单中提到的自定义 header,但没有任何反应。
您可以选择 Kingfisher 用于缓存的密钥。因此,创建一个预签名的 s3 url,然后在加载图像时使用您的 s3 密钥作为缓存,而不是完整的预签名 url.
let getPreSignedURLRequest = AWSS3GetPreSignedURLRequest()
getPreSignedURLRequest.bucket = media.bucket
getPreSignedURLRequest.key = media.key
getPreSignedURLRequest.httpMethod = .GET
getPreSignedURLRequest.expires = Date(timeIntervalSinceNow: 3600) // Change the value of the expires time interval as required
AWSS3PreSignedURLBuilder.default().getPreSignedURL(getPreSignedURLRequest).continueWith { (task:AWSTask<NSURL>) -> Any? in
if let error = task.error as NSError? {
print("Error: \(error)")
return nil
}
if let presignedURL = task.result {
DispatchQueue.main.async {
self.imageView.kf.indicatorType = .activity
let resource = ImageResource(downloadURL: URL(string: presignedURL.absoluteString!)!, cacheKey: media.key)
self.imageView.kf.setImage(with: resource)
}
}
return nil
}