简体   繁体   English

使用Firebase存储上传自定义元数据

[英]Uploading custom metadata with Firebase Storage

I have an app where I want to store a caption with a photo, but in my case, I'm using FIRStorage to store the photos. 我有一个应用程序,我想存储带照片的标题,但在我的情况下,我使用FIRStorage存储照片。 Everything's working there, but I want to store the caption in the photo metadata. 一切都在那里工作,但我想将标题存储在照片元数据中。 Don't ask why, it just makes sense for my project specifically. 不要问为什么,它对我的​​项目特别有意义。

let meta = FIRStorageMetadata.init(dictionary: ["customMetadata" :
["caption" : self.textField.text!]])
                let imageRef = storageRef.child(iid)
            imageRef.put(uploadData, metadata: meta, completion: {     (metadata, error) in
                    if error != nil {
                        //failure
                        print(error)
                        return
                    } else {

                    //success
                    print(metadata)

                }
            })

As you can see, I'm even setting up the metadata constant exactly how Firebase tells us in their documentation. 正如您所看到的,我甚至将元数据设置为Firebase在文档中告诉我们的方式。 When I pass meta into metadata in the .put , why does it not use my custom metadata? 当我将元数据传递到.put中的元数据时,为什么它不使用我的自定义元数据? Thanks for the help guys 谢谢你的帮助

Got it! 得到它了! I just did it wrong previously. 我以前做错了。
Here is the solution: 这是解决方案:

var meta = FIRStorageMetadata()
meta.customMetadata = ["caption" : self.textField.text!]

Then you pass meta into metadata parameter in .put 然后将meta传递给.put元数据参数

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

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