我正在使用 firebase 并制作一个应用程序,使用户能够保存 6 个个人资料图像。
现在,我已经准备了 6 个 imageView,用户可以通过点击每个 imageView 来简单地添加他们的图像。
我想将图像保存到 firebase 存储并将 URL 下载到 Firebase 数据库。从技术上讲,我可以保存它,但我不确定如何构建数据库和图像文件的名称。
目前,我使用 Dateformatter 命名图像文件(如“yyyy-MM-dd”“HH:mm:ss”.jpg) 并将下载 URL 设置为数据库,例如 "yyyy-MM-dd''HH:mm:ss": "downloadURL"
数据库结构如下:
"User" : {
“user’s uid” : {
"ImgURLs” : {
"2018-09-02_21:59:80" : “(here is the url)”,
"2018-09-02_22:05:72" : "(here is another url)",
"2018-09-02_23:49:54” : "(here is another url)"
},
}
}
但是通过这种方式,我不知道如何为这 6 个 Imageviews 相应地检索数据。
如果我的问题有意义的话,有没有办法实现这个。
最佳答案
对 URL 存储方式的更改应该提供答案
users :
uid :
userName: "some name"
ImgURLs :
-Jiokoisd094k //key created with childByAutoId
url : “(here is the url)”
timestamp : "2018-09-02_21:59:80"
-k0k4000od0if //key created with childByAutoId
url : "(here is another url)"
timestamp : "2018-09-02_22:05:72"
有了这个,只要您知道用户的 uid,就可以在 users/uid/ImgURLs 访问他们的图片 url。这还允许您存储有关每个图像的时间戳和其他信息;也许是标题的子节点:每个子节点中的“该死,你看起来不错”。
根据用例,如果您需要查询这些节点,最好对数据进行非规范化并将它们存储在单独的节点中
users :
uid :
userName: "some name"
urls :
uid :
-Jiokoisd094k //key created with childByAutoId
url : “(here is the url)”
timestamp : "2018-09-02_21:59:80"
-k0k4000od0if //key created with childByAutoId
url : "(here is another url)"
timestamp : "2018-09-02_22:05:72"
关于ios - firebase 数据库结构的好方法,以便按日期排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52136783/