我正在尝试从 S3 下载图像以缓存它。这没有缓存是有效的:
let manager = AWSUserFileManager.defaultUserFileManager()
let content = manager.contentWithKey("public%2F" + userID + "_profile.jpg")
content.getRemoteFileURLWithCompletionHandler({[weak self](url: NSURL?, error: NSError?) -> Void in
guard let url = url else {
print("Error getting URL for file. \(error)")
return
}
let imageData = NSData(contentsOfURL: url)
imageView.image = UIImage(data: imageData!)
})
这与缓存不起作用:
let content = manager.contentWithKey("public%2F" + userID + "_profile.jpg")
if !content.cached {
print("Not Cached")
imageView.image = UIImage(named: "UserIcon")
content.downloadWithDownloadType(AWSContentDownloadType.IfNewerExists, pinOnCompletion: false, progressBlock: nil, completionHandler: { (content: AWSContent?, data: NSData?, error: NSError?) -> Void in
print("Cached")
imageView.image = UIImage(data: data!)
})
} else {
print("Cached2")
imageView.image = UIImage(data: content.cachedData)
}
完成后出现错误:域:“com.amazonaws.AWSContentManager.ErrorDomain” - 代码:1
我的代码有什么问题?