简体   繁体   English

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

[英]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.

相关问题 如何允许访客 Amplify 用户使用 AWS Amplify iOS 开发工具包从我的 S3 存储桶下载文件? - How can I allow guest Amplify users to download files from my S3 bucket using the AWS Amplify iOS SDK? 适用于iOS的AWS开发工具包:无法列出S3存储桶中的文件 - AWS SDK for iOS: unable to list the files in an S3 bucket 如何从 iOS 中的 AWS S3 存储桶下载文件? - How to download a file from a AWS S3 bucket in iOS? 如何使用iOS SDK将AWS S3文件从一个存储桶复制到另一个存储桶 - How to copy an AWS S3 file from one bucket to another using iOS SDK 无法通过iOS 11.4.1将文件上传到S3存储桶(AWS-IOS-SDK-2.6.24) - Unable to upload files into S3 bucket through iOS 11.4.1 (AWS-IOS-SDK-2.6.24) 一旦文件放到文件中,如何使用AWS iOS SDK收听S3存储桶下载文件 - How to use AWS iOS SDK to listen to an S3 bucket an download a file once it gets put there 如何使用 AWS amplify 从只读 AWS S3 Bucket 安全地将图像下载到 iOS 应用程序? - How to securely download images from read-only AWS S3 Bucket to an iOS app using AWS amplify? 从 S3 存储桶下载 iOS 依赖项 - Download iOS dependencies from S3 bucket 在Amazon S3存储桶中上传背景图片(背景模式),而无需在iOS Swift中使用AWS开发工具包 - Background image (Background Mode) uploading in Amazon S3 bucket without using AWS SDK in iOS Swift IOS从AWS S3下载图像 - IOS Download Images From AWS S3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM