首页 > 解决方案 > 从亚马逊 aws s3 存储桶将照片下载到 ios 应用程序时出错

问题描述

我正在开发 ios 应用程序,并且是使用 amazon s3 存储桶的新手,我正在使用它存储照片,但是当我尝试将存储桶中的照片下载到我的应用程序的图像视图中时,它会输出“操作无法(com.amazonaws.AWSServiceErrorDomain 错误 11.)”在控制台中。

我在网上四处寻找,人们也有类似的问题,但没有找到任何解决问题的方法。

func getPicture(){
        let downloadedFile = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("test.png")
        let transferManager = AWSS3TransferManager.default()
        if let downloadRequest = AWSS3TransferManagerDownloadRequest(){
            downloadRequest.bucket = bucket
            downloadRequest.key = currentQuestionData?._userId!
            downloadRequest.downloadingFileURL = downloadedFile
                transferManager.download(downloadRequest).continueWith(block: { (task: AWSTask<AnyObject>) -> Any? in
                    if( task.error != nil){
                        print(task.error!.localizedDescription)
                        print(self.currentQuestionData!._userId)
                        return nil
                    }

                    print(task.result!)

                    if let data = NSData(contentsOf: downloadedFile){
                        print("getting image")
                        DispatchQueue.main.async(execute: { () -> Void in
                            self.imageView.image = UIImage(data: data as Data)
                        })
                    }
                    return nil
                })
        }
    }

它应该将图像加载到 imageView 上,但它给出了错误“操作无法完成(com.amazonaws.AWSServiceErrorDomain 错误 11。)”

标签: swiftxcodeamazon-s3aws-sdk

解决方案


推荐阅读