swift - iOS 应用程序:如何使用 kingfisher/sdwebimage 下载 aws s3 映像
问题描述
我想使用 kingfisher 在我的 swiftui 项目中的 collectionview 或列表中显示来自 aws s3 保护文件夹的图像。但是我找不到将图像显示为 aws 需要在请求中包含其他标头的解决方案。我尝试添加 Cheatsheet 中提到的自定义标题,但没有任何反应。
解决方案
您可以选择 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
}
推荐阅读
- php - php while循环在shell中运行但不在浏览器上
- android - android 适配器 convertView 中的 ImageView 测量为 0 宽度和 0 高度
- dialogflow-es - Dialogflow,如何在另一个 Intent 中重用 Intent
- ios - 图像仅全屏一次
- sql-server - Is there anything like multiblock readings in SQL Server?
- ruby-on-rails - using axlsx gem how to generate excel in landscape orientation
- python - Dynamically sized array of objects in Cython
- php - How to turn a 3d matrix into a string?
- php - PHP 表单 + REPLACE INTO mySQL 不起作用,但另一个页面上的相同查询是有效的.. 有什么我遗漏的吗?
- bash - How can I use my C program's binary file after as a filter?