将Firestore数据存储在模拟

时间:2019-06-22 19:38:33

标签: angular typescript firebase google-cloud-firestore

当前,我正在使用包含数组的模拟在应用程序内部分发数据(您可以在下面的代码中找到)。我在需要它的每个组件中遍历此数组。

export const CASES: Case[] = [
  { id: 0,
    name: 'Diesel',
    portfolioImage: '/assets/images/portfolio/diesel.png',
    image: '/assets/images/diesel.jpg',
    image2: '/assets/images/diesel/diesel-sunflower.png',
    image3: '/assets/images/diesel/diesel-cap.png',
    link: '/cases/diesel',
    header: 'black'
  },

  { id: 1,
    name: 'WeWork Berlin',
    portfolioImage: '/assets/images/portfolio/berlin.png',
    image: '/assets/images/berlin.jpg',
    image2: '/assets/images/wework/berlin-logo.png',
    image3: '/assets/images/wework/berlin-building.png',
    link: '/cases/wework',
    header: 'white'
  },

  { id: 2,
    name: 'Fritzhansen',
    portfolioImage: '/assets/images/portfolio/fritzhansen.png',
    image: '/assets/images/fritzhansen.jpg',
    image2: '/assets/images/fritzhansen/women.png',
    image3: '/assets/images/fritzhansen/chairs.jpeg',
    link: '/cases/fritzhansen',
    header: 'white'
  },

  { id: 3,
    name: 'Savum',
    portfolioImage: '/assets/images/portfolio/savum.png',
    image: '/assets/images/savum/savum-front.png',
    image2: '/assets/images/savum/savum-logo.png',
    image3: '/assets/images/savum/savum-iphone.png',
    link: '/cases/savum',
    header: 'black'
  },

  { id: 4,
    name: 'Eskay',
    portfolioImage: '/assets/images/portfolio/eskay.png',
    image: '/assets/images/eskay.jpg',
    image2: '/assets/images/eskay/front.jpg',
    image3: '/assets/images/eskay/inner.jpg',
    link: '/cases/eskay',
    header: 'black'
  },

  { id: 5,
    name: 'Diesel Fashion',
    portfolioImage: '/assets/images/portfolio/diesel-snd.png',
    image: '/assets/images/diesel-snd.png',
    image2: '/assets/images/diesel/diesel-sunflower.png',
    image3: '/assets/images/diesel/diesel-cap.png',
    link: '/cases/template',
    header: 'black'
  },

  { id: 6,
    name: 'Mobilia',
    portfolioImage: '/assets/images/portfolio/mobilia.png',
    image: '/assets/images/mobilia.jpg',
    image2: '/assets/images/mobilia/green.jpg',
    image3: '/assets/images/mobilia/pink.jpg',
    link: '/cases/mobilia',
    header: 'black'
  },

  { id: 7,
    name: 'Rarekind',
    portfolioImage: '/assets/images/portfolio/rarekind.png',
    image: '/assets/images/rarekind.jpg',
    image2: '/assets/images/rarekind/tube.png',
    image3: '/assets/images/rarekind/red.png',
    link: '/cases/rarekind',
    header: 'black'
  },
];

我想要的是将此阵列与Firebase一起存储(而不是图像链接,firebase存储?),以便能够将其用作一种内容管理系统来更新条目。

是否可以将此列表与Firebase的存储(而不是资产文件夹)一起插入到Firestore中?

如何在init上读取此数据并将其存储在这种模拟中以再次自动分发? -甚至可以将图像存储在这样的阵列中吗?

确切地说,我该怎么办。

  1. 从存储中获取图像及其分配的条目
  2. 将此捆绑软件作为单个Case插入给定的模拟

我可以实现这种方法吗?还是有另一种方法可以达到相同的目的?

1 个答案:

答案 0 :(得分:1)

  

是否可以将此列表与Firebase的存储(而不是资产文件夹)一起插入到Firestore中?

是的,但是它可能无法100%地按照您的想象来工作。当您将图像上传到Firebase Storage时,它会提供一个URL来检索该图像。然后,您可以使用JSON对象将该URL保存在Firebase Realtime DB中,就像您问题中的那个对象一样。您的应用将需要查询Firebase来检索JSON,然后对特定图像进行后续请求。

如果资产很小,您可能想探索将图像存储为base64数据URI,但是性能非常重要,因此YMMV。