Firebase存储下载响应错误

时间:2018-05-22 15:17:32

标签: swift firebase firebase-storage ios11.3

我已成功将图像上传到firebase存储,但无法成功下载图像。

我尝试在Firebase存储指南中以所有三种建议方式下载图像:

1)在内存中下载到NSData 2)下载到表示设备上文件的NSURL 3)生成代表在线文件的NSURL

下面是两个不同尝试的例子:

func loadProfileImage() {
        guard let currentUser = Auth.auth().currentUser else { return }
        let profilePhotoFile = "ProfileImages/" + currentUser.uid
        let reference = Storage.storage().reference(withPath: profilePhotoFile)

#1st尝试下载到内存:

    reference.getData(maxSize: 1 * 1024 * 1024) { (data, error) in
        if let error = error {
            print("an error occurred: \(error)")
            print("see data response: \(data)")
        }  else {
            self.profileView.image = UIImage(data: data!)
        }
     }

#2nd尝试下载网址:

     reference.downloadURL { (url, error) in
        if let error = error {
            print(error)
        } else {
            self.profileView.sd_setImage(with: url, placeholderImage: 
           #imageLiteral(resourceName: "placeHolderProfileView")) { 
         (image, error, type, reference2) in
                print("reference location of image in the google 
     bucket: \(reference2)")
                print("error retrieving image: \(String(describing: 
            error))")
                print("type: \(type)")
                print("image details: \(String(describing: image))")
            }

        }

    }
}

还尝试使用alamofire而不是SDWebImage来查看错误代码是否相同,并且它是相同的,如下所示:

错误域= FIRStorageErrorDomain代码= -13000"发生未知错误,请检查服务器响应。" UserInfo = {object = ProfileImages / 6I2RhzFI3edYNph9J4WsaXXXX,ResponseErrorCode = 100,bucket = bXXXX-production.appspot.com,NSLocalizedDescription =发生未知错误,请检查服务器响应。,ResponseErrorDomain = NSPOSIXErrorDomain,_kCFStreamErrorDomainKey = 1,NSErrorPeerAddressKey = {length = 28,capacity = 28,bytes = 0x1c1e01bb000000002607f8b040090813 ... 0000200a00000000},_ kCFStreamErrorCodeKey = 100}

我已检查并重新检查了Google存储桶位置,并认为我的参考位置正确(使用与正常工作的上传文件路径相同)。

非常感谢任何帮助

1 个答案:

答案 0 :(得分:0)

意识到错误发生在上传图片时包含的标题中:

我最初在上传中列出了以下内容,通过评论它们我能够成功下载SDWebImage和vbuzze的建议。

让uploadMetadata = StorageMetadata() uploadMetadata.contentType =" image / jpeg" uploadMetadata.customMetadata = ["个人资料名称" :currentUser.displayName]为? [String:String]