Firebase存储如何存储和检索图像 [英] Firebase Storage How to store and Retrieve images

查看:75
本文介绍了Firebase存储如何存储和检索图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Firebase上存储和查看图像?

How to store and view images on firebase?

推荐答案

更新(20160519): Firebase刚刚发布了一项名为

Update (20160519): Firebase just released a new feature called Firebase Storage. This allows you to upload images and other non-JSON data to a dedicated storage service. We highly recommend that you use this for storing images, instead of storing them as base64 encoded data in the JSON database.

您当然可以!根据图像的大小,您可以选择以下几种方式:

You certainly can! Depending on how big your images are, you have a couple options:

1.对于较小的图像(小于10mb)

我们有一个在此处执行示例项目: https://github.com/firebase/firepano

We have an example project that does that here: https://github.com/firebase/firepano

一般方法是在本地加载文件(使用FileReader),这样便可以将其存储在Firebase中,就像存储其他任何数据一样.由于图像是二进制文件,因此您需要获取base64编码的内容,以便将其存储为字符串.甚至更方便的是,您可以将其存储为数据:URL ,然后即可将其放入作为img标签的src(这就是示例的作用)!

The general approach is to load the file locally (using FileReader) so you can then store it in Firebase just as you would any other data. Since images are binary files, you'll want to get the base64-encoded contents so you can store it as a string. Or even more convenient, you can store it as a data: url which is then ready to plop in as the src of an img tag (this is what the example does)!

2.放大图片

Firebase的限制为10mb(由utf8编码的字符串数据).如果图像较大,则必须将其分成10mb的块.没错,尽管Firebase针对频繁更改的小字符串(而不是多兆字节的字符串)进行了更优化.如果您有大量的大型静态数据,则绝对建议您使用S3或CDN.

Firebase does have a 10mb (of utf8-encoded string data) limit. If your image is bigger, you'll have to break it into 10mb chunks. You're right though that Firebase is more optimized for small strings that change frequently rather than multi-megabyte strings. If you have lots of large static data, I'd definitely recommend S3 or a CDN instead.

这篇关于Firebase存储如何存储和检索图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆