[英]Unable to download from subfolder of a bucket using AWS S3 iOS SDK
Using the AWS S3 SDK (via Cocoapods) v2.8.0 but I can't get it to download images from within a sub folder in the bucket.使用 AWS S3 SDK(通过 Cocoapods)v2.8.0 但我无法从存储桶的子文件夹中下载图像。 The code works fine for downloading within the root of the bucket
该代码适用于在存储桶的根目录中下载
func downloadData(imageName: String, completion: @escaping (Bool) -> () ) {
let expression = AWSS3TransferUtilityDownloadExpression()
expression.progressBlock = {(task, progress) in DispatchQueue.main.async(execute: {
print("Download in process: \(progress.fractionCompleted*100)% complete")
})
}
var completionHandler: AWSS3TransferUtilityDownloadCompletionHandlerBlock?
completionHandler = { (task, URL, data, error) -> Void in
DispatchQueue.main.async(execute: {
if let error = error?.localizedDescription {
print("Error in completion of download: \(error)")
}
print("Completion Response: \(task.response)")
if let responseData = data {
if let image = UIImage.init(data: responseData) {
self.saveImage(imageName: imageName, image: image)
completion(true)
}
}
completion(false)
})
}
transferUtility.downloadData(
fromBucket: "myBucketName",
key: "mySubFolder/" + imageName,
expression: expression,
completionHandler: completionHandler
).continueWith {
(task) -> AnyObject? in if let error = task.error {
print("Error: \(error.localizedDescription)")
}
if let _ = task.result {
}
return nil;
}
}
I'm getting a 404 with the above code and the following error.我收到带有上述代码的 404 和以下错误。
Error in completion of download: The operation couldn’t be completed. (com.amazonaws.AWSS3TransferUtilityErrorDomain error 2.)
Solved: The above code is correct but I was omitting the file extension from my key.已解决:上面的代码是正确的,但我从我的密钥中省略了文件扩展名。 In the root folder it didn't seem to be to fussy so would accept "ImageName" or "ImageName.jpg" but when adding the subfolder on it didn't like this and only accepted "SubFolder/ImageName.jpg".
在根文件夹中,它似乎并不繁琐,因此会接受“ImageName”或“ImageName.jpg”,但在添加子文件夹时不喜欢这样,只接受“SubFolder/ImageName.jpg”。
Adding the file extension solved the problem.添加文件扩展名解决了这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.