Firebase存储错误

Pra*_*tha 1 ios firebase swift firebase-storage

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)
        }
}
Run Code Online (Sandbox Code Playgroud)

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

它抛出以下错误:

*** 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
Run Code Online (Sandbox Code Playgroud)

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

Pra*_*tha 5

事实证明,我们无法将文件放在根存储节点中.需要创建子节点,然后才能保存文件.Firebase文档中明确提到我忽略了它.

例如

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)
        }
}
Run Code Online (Sandbox Code Playgroud)