Firebase putData函数 [英] Firebase putData function
本文介绍了Firebase putData函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Xcode,Swift 3.我正在尝试为图像(PNG)调用putData,这是我的代码:
I am using Xcode, Swift 3. I am trying to call putData for an image (PNG), and this is my code :
let storageRef = Storage.storage().reference().child("ProductsImages").child(product.UniqueID()).child("MainImage.png")
if let mainChosenImage = self.selectedImageToUpload
{
if let uploadData = UIImagePNGRepresentation(mainChosenImage)
{
storageRef.putData(uploadData, metadata: nil, completion:
{
(StorageMetaData, error) in
if error != nil
{
print(error)
return
}
self.mainImageURL = StorageMetaData?.downloadURL()?.absoluteString
})
}
}
行为是这样-图像可以很好地保存到Firebase,但是不调用完成".含义-它不会检查错误!= nil,更重要的是-它不会使用绝对URL字符串实例化mainImageURL.
And the behavior is this - the image is saved fine to Firebase, but "completion" isn't called. Meaning - it won't check if error != nil, and more importantly - it won't instantiate mainImageURL with the absolute URL string.
关于如何解决此问题的任何想法?
Any ideas on how to fix this ?
推荐答案
完成应如下所示
if let uploadData = UIImagePNGRepresentation(self.myImageView.image!) {
storageRef.put(uploadData, metadata: nil) { (metadata, error) in
if error != nil {
print("error")
} else {
// your uploaded photo url.
}
}
这篇关于Firebase putData函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文