如何在Firebase上存储和查看图像? [英] How to store and view images on firebase?

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

问题描述

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

更新(20160519):

em> Firebase刚刚发布了一项名为 Firebase存储的新功能。这使您可以将图像和其他非JSON数据上传到专用存储服务。我们强烈建议您使用它来存储图像,而不是将它们作为base64编码数据存储在JSON数据库中。



您当然可以!根据你的图片有多大,你有几个选择:

1。对于较小的图片(10MB以下)



我们有一个示例项目,它在这里: https://github.com/firebase/firepano



一般的方法是在本地加载文件(使用FileReader),然后就可以将其存储在Firebase中,就像其他数据一样。由于图像是二进制文件,因此您需要获取base64编码的内容,以便将其存储为字符串。或者更方便,您可以将其保存为 data:url ,然后准备好作为一个img标签的src(这就是这个例子)!

2。对于较大的图片



Firebase确实有一个10MB(utf8编码的字符串数据)限制。如果你的图像更大,你将不得不把它分成10mb大块。你说得对,虽然Firebase更适合频繁更换的小字符串,而不是数兆字节的字符串。如果你有很多大的静态数据,我肯定会推荐S3或者CDN。


How to store and view images on 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. For smaller images (under 10mb)

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

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. For larger images

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天全站免登陆