我尝试将多个图片从库上传到Firebase存储。上传过程完美无缺,所有图片都在Firebase存储上,但是当我尝试下载图片网址链接以保存在数据库中时,它显示为零。请帮我解决这个问题?非常感谢
for imageData in ArrayMedia {
print(imageData)
let filePath = "\(currentUserId)/\(key)"
let data = UIImageJPEGRepresentation(imageData, 0.3)
let metadata = StorageMetadata()
metadata.contentType = "image/jpg"
storageReference.child(filePath).putData(data!, metadata: metadata, completion: { (metaData, error) in
print(metadata)
if error != nil {
print(error?.localizedDescription as Any)
} else {
let PhotoUrl = metadata.downloadURL()?.absoluteString // GOT NIL IN THIS LINE
print(PhotoUrl)
let value = ["Username" : currentUserName, "UserId" : currentUserId, "Text" : self.tvPost.text] as [String : Any]
databaseReference.child("PendingPost").child(currentUserId).child(key).updateChildValues(value)
databaseReference.child("PendingPost").child(currentUserId).child(key).child("Images").child(key).setValue(["PhotoUrl": PhotoUrl])
}
self.showAlert()
})
}
答案 0 :(得分:0)
请尝试使用此功能:
storageRef.child(path).putData(data, metadata: metaData){ (metaData,error) in
if let error = error {
print(error.localizedDescription)
return
} else {
let downloadURL = metaData!.downloadURL()!.absoluteString
}
}
它对我有用。