简体   繁体   English

在Firebase中更改存储元数据中的值

[英]Changing values in storage metadata in Firebase

In my iOS app, users can upload profile pictures which are upload to the storage in Firebase. 在我的iOS应用中,用户可以上传个人资料图片,然后上传到Firebase的存储中。 I have saved the URL of the profile pictures on to the database so I can know which URLs correspond to which users using the following code: 我已经将个人资料图片的URL保存到数据库中,因此可以使用以下代码知道哪些URL对应于哪些用户:

    let storageRef = FIRStorage.storage().reference()
    let fileRef = storageRef.child("pages/").child(UUID().uuidString + ".jpg")

    _ = fileRef.put(UIImageJPEGRepresentation(image, 0.75)!, metadata: nil) { (metadata, error) in
        if let error = error {
            SCLAlertView().showError("Error", subTitle: error.localizedDescription)
            return
        } else {
            let downloadURL = metadata!.downloadURL()
            let  dictionary: [String: Any] = ["UserID": uid, "PageName": self.pageTitle.text!, "PFPURL": downloadURL!, "Tags": self.tags, "Likes": [uid]]

            let reference = FIRDatabase.database().reference().child("Pages").childByAutoId()
            reference.setValue(dictionary, withCompletionBlock: { (error, ref) in
                if let error = error {
                    SCLAlertView().showError("Error", subTitle: error.localizedDescription)
                    return
                }
                self.performSegue(withIdentifier: "setupComplete", sender: self)
            })

        }
    }

However, I would like these pictures to be editable. 但是,我希望这些图片是可编辑的。 Is it possible I can replace the image in the storageRef yet still keep the same URL? 是否可以替换storageRef中的图像,但仍保留相同的URL? If so, how would I accomplish that? 如果是这样,我将如何实现? Thanks! 谢谢!

You can't keep the same download URL. 您不能保留相同的下载URL。 When the photo is edited, you'll need to update the value of "PFPURL" in the database to be the new URL. 编辑照片后,您需要将数据库中的“ PFPURL”值更新为新的URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM