简体   繁体   English

Firebase:存储多个图像 URL 的最佳方式

[英]Firebase : Best way to store multiple image URLs

Just a quick message to ask you about how to store images URLs in Firebase Database for later use.只是一条简短的消息,询问您如何在 Firebase 数据库中存储图像 URL 以备后用。 Let me explain:让我解释:

I use Firebase Storage to store Images but store their respective URLs in Firebase Database, separately from Firebase Storage (as I have been reading on here it was the way to do it).我使用 Firebase 存储来存储图像,但将它们各自的 URL 存储在 Firebase 数据库中,与 Firebase 存储分开(正如我在这里阅读的那样)。
So in Firebase Database I have a "ItemPictures" Node where I want to store up to 5 pictures URLs per Item.因此,在 Firebase 数据库中,我有一个“ItemPictures”节点,我想在其中为每个项目存储最多 5 个图片 URL。

But I don't know what is the best way to store multiple image URLs of a same Item:但我不知道存储同一 Item 的多个图像 URL 的最佳方法是什么:
- Creating a List with random ids using push() (and then having to manage deleting manually the picture'sURL when it gets updated). - 使用 push() 创建一个带有随机 ID 的列表(然后在更新图片时必须手动删除图片的 URL)。
- Creating a "Picture" Object with 5 URLs String values, making it easier to locate and navigate through. - 创建一个带有 5 个 URL 字符串值的“图片”对象,使其更容易定位和导航。

The thing is that later on I will need those URLs to populate a View Pager with the 5 pictures.问题是,稍后我将需要这些 URL 来用 5 张图片填充 View Pager。

Cheers,干杯,

Andy安迪

using an ArrayList will be a better one使用 ArrayList 会更好

ArrayList<String> images = new ArrayList<>();
                images.add("img1url");
                images.add("img2url");
                images.add("img3url");
                images.add("img4url");
                images.add("img5url");

The simplest way is to store each image object with unique key and inside it have five keys with values 1,2,3,4,5 respectively.最简单的方法是用唯一的键存储每个图像对象,其中有五个键,分别为 1、2、3、4、5。 Then you can easily fetch the desired URL for particular image with ID by :然后,您可以通过以下方式轻松获取具有 ID 的特定图像的所需 URL:

 firebaseSnapshot.val().ID.1; firebaseSnapshot.val().ID.2; firebaseSnapshot.val().ID.3; firebaseSnapshot.val().ID.4; firebaseSnapshot.val().ID.5;

To further improve the performance you can index the image IDs as they are going to grow larger in number.为了进一步提高性能,您可以索引图像 ID,因为它们的数量会越来越大。 This has been done in the following question.这已在以下问题中完成。

enter link description here 在此处输入链接描述

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

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