2016-07-19 156 views
0

FirebaseStorage波德版(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中選擇的圖像,並試圖將圖像數據保存到存儲火力。 。作爲火力文檔說明(從數據Docs Reference)上傳內存部分

它拋出以下錯誤:

*** 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 

使用前的工作相同的代碼,我不知道現在的問題。

+0

您是不是打印(圖片)? ..並驗證它是否爲零 –

回答

4

事實證明,我們不能把文件放在根存儲節點。要創建子節點,那麼只有你可以保存文件。這顯然mentioned in the Firebase docs不知何故,我忽略了它。

E.g

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) 
     } 
}