gpt4 book ai didi

ios - 无法使用 AWS S3 iOS SDK 从存储桶的子文件夹下载

转载 作者:行者123 更新时间:2023-11-29 05:26:56 28 4
gpt4 key购买 nike

使用AWS S3 SDK(通过Cocoapods)v2.8.0,但我无法让它从存储桶的子文件夹中下载图像。该代码可以很好地在存储桶的根目录中下载

    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;
}
}

我收到包含上述代码和以下错误的 404 错误。

Error in completion of download: The operation couldn’t be completed. (com.amazonaws.AWSS3TransferUtilityErrorDomain error 2.)

最佳答案

已解决:上面的代码是正确的,但我省略了 key 中的文件扩展名。在根文件夹中,它似乎并不挑剔,因此会接受“ImageName”或“ImageName.jpg”,但在其上添加子文件夹时不喜欢这样,只接受“SubFolder/ImageName.jpg”。

添加文件扩展名解决了问题。

关于ios - 无法使用 AWS S3 iOS SDK 从存储桶的子文件夹下载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58070661/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com