Firebase存储错误 [英] Firebase storage error

查看:99
本文介绍了Firebase存储错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

FirebaseStorage Pod版本(1.0.1)

var storageRef: FIRStorageReference! = FIRStorage.storage().reference()


let uploadTask = storageRef.putData(UIImagePNGRepresentation(image)!, metadata: nil) { metadata, error in
        if (error != nil) {

        } else {
            let downloadURL = metadata!.downloadURL
            print(downloadURL)
        }
}

我只是从ImagePicker中选择了一个图像,然后尝试将图像数据保存到Firebase存储器中.如Firebase文档中所示.(文档参考) 从内存中的数据部分.

I simply selected a image from ImagePicker and tried to save Image data to the firebase storage. As illustrated in firebase docs.(Docs Reference) Upload from data in memory section.

它抛出以下错误:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[1]'
*** First throw call stack:
(
    0   CoreFoundation                      0x02025494 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x03eb2e02 objc_exception_throw + 50
    2   CoreFoundation                      0x01f0c6d2 -[__NSPlaceholderDictionary initWithObjects:forKeys:count:] + 386
    3   CoreFoundation                      0x01f2095b +[NSDictionary dictionaryWithObjects:forKeys:count:] + 75
    4   FirePlay                            0x001e42bc -[FIRStorageUploadTask enqueue] + 815
    5   FirePlay                            0x001e010c -[FIRStorageReference putData:metadata:completion:] + 880

以前使用过的相同代码.我不确定现在是什么问题.

The same code used to work before. I am not sure what's the problem now.

推荐答案

事实证明,我们无法将文件放在根存储节点中.需要创建子节点,然后只有您可以保存文件.很明显,在Firebase文档中提到了 ,我以某种方式忽略了它.

Turns out that we can't put files in root storage node. need to create child node and then only you can save the file. It was clearly mentioned in the Firebase docs somehow I overlooked it.

例如

let mountainsRef = storageRef.child("mountains.jpg")

let uploadTask = mountainsRef.putData(UIImagePNGRepresentation(image)!, metadata: nil) { metadata, error in
        if (error != nil) {

        } else {
            let downloadURL = metadata!.downloadURL
            print(downloadURL)
        }
}

这篇关于Firebase存储错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆