Firebase存储上传错误:“对象albumNum / 1不存在。”

时间:2016-09-03 11:40:18

标签: swift firebase firebase-storage

这是我的上传代码

    func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
    let albumImageRef = FIRStorage.storage().referenceForURL("gs://tiat-ea6fd.appspot.com")
        .child("albumNum")
    self.dismissViewControllerAnimated(true, completion: nil)
    let image = info[UIImagePickerControllerOriginalImage] as! UIImage
    let newImage = UIImageJPEGRepresentation(image, 3.0)
    self.metadata.contentType = "image/jpeg"
    print("\(values + 1)")
    albumImageRef.child("\(values + 1)").putData(newImage!, metadata: self.metadata){metadata, error in
        if error == nil {self.collectionView.reloadData()}
        else {print(error?.localizedDescription)}

    }

}

当我运行代码时,它说

Optional("Object albumNum/1 does not exist.")

我的数据库中没有任何内容

1 个答案:

答案 0 :(得分:0)

您的values对象是什么类型的?

如果类型为Int?(可选整数)或其他可选类型,您可以在.putData引用上调用albumImageRef.child("\(values + 1)")之前尝试展开它:

guard let values = values else { return }