我已将图片上传到amazonS3广告位。我正在尝试下载指定用户的个人资料图片。 Xcode表示文件无法打开,因为URL类型http不受支持..我是否忽略了某些内容?
func retrieveProPic(proPicString: String, userID: String){
let downloadRequest = AWSS3TransferManagerDownloadRequest()
downloadRequest.bucket = "profilepicturetest1"
downloadRequest.key = userID
let proPicURL = NSURL(string: proPicString)
if let picURL = proPicURL {
downloadRequest.downloadingFileURL = picURL
}
let transferManager = AWSS3TransferManager.defaultS3TransferManager()
transferManager.download(downloadRequest).continueWithBlock { (task) -> AnyObject? in
if let error = task.error {
print("Failed to download because of (\(error))")
}
if task.result != nil {
if let data = NSData(contentsOfURL: downloadRequest.downloadingFileURL)
{
self.proPicImage = UIImage(data: data)
dispatch_async(dispatch_get_main_queue()){
self.tableView.reloadData()
}
}
print("made it to have result")
} else {
print ("Unexpected empty result")
}
return nil
}
}
答案 0 :(得分:0)
将以下内容添加到Info.plist
:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
或者如果您想手动输入它们:
App Transport Security Settings
作为字典添加到您的媒体资源列表中。+
,然后选择Allow Arbitrary Loads
。YES
。这应仅用作临时解决方案,因为建议使用与网络应用程序的安全连接。
答案 1 :(得分:0)
func retrieveProPic(proPicString: String, userID: String){
let downloadedFilePath = NSTemporaryDirectory().stringByAppendingString("downloaded-myImage.jpg")
let downloadedFileURL = NSURL(fileURLWithPath: downloadedFilePath)
let downloadRequest = AWSS3TransferManagerDownloadRequest()
downloadRequest.bucket = "profilepicturetest1"
downloadRequest.key = userID
downloadRequest.downloadingFileURL = downloadedFileURL
let transferManager = AWSS3TransferManager.defaultS3TransferManager()
transferManager.download(downloadRequest).continueWithBlock { (task) -> AnyObject? in
if let error = task.error {
print("Failed to download because of (\(error))")
}
if task.result != nil {
if let data = NSData(contentsOfURL: downloadedFileURL)
{
self.proPicImage = UIImage(data: data)
dispatch_async(dispatch_get_main_queue()){
self.tableView.reloadData()
}
}
print("made it to have result")
} else {
print ("Unexpected empty result")
}
return nil
}