将base64编码的图像保存到Firebase存储 [英] Save base64 encoded image to Firebase Storage

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

问题描述

使用firebase 3.0.x,是否可以将base64编码的图像保存到新的Firebase存储服务?



我使用画布在浏览器中调整图像大小然后上传它们,并以base64 jpeg格式输出。我知道Storage api可以接受Blob,但是我的当前项目需要IE9支持。 解决方案

最新版本的Firebase SDK支持base64图片上传。只需使用Firebase存储中的 putString 方法即可。 $ b

https://firebase.google.com/docs/reference/js/firebase.storage



有一点需要注意的是,有时候你会有一个base64字符串和不必要的空格。例如,我发现cordova Camera插件返回base64不必要的空格。 Storage SDK将无法上传,因为JavaScript不能执行原生的 atob 函数 - Firebase JS在底层实现的功能。你将不得不去掉空白 - 参见 DOM异常5 JavaScript中的有效base64图像字符串中的字符错误


Using firebase 3.0.x, is it possible to save a base64 encoded image to the new Firebase Storage service?

I am using canvas to resize images in the browser prior to uploading them, and output them as a base64 jpeg. I know that the Storage api can accept Blobs, but IE9 support is needed for my current project.

解决方案

The latest version of the Firebase SDK supports base64 image uploads. Simply use the putString method from Firebase Storage.

https://firebase.google.com/docs/reference/js/firebase.storage

One small caveat is that sometimes you'll have a base64 String with unnecessary whitespace. For example, I've found that the cordova Camera plugin returns base64 with unnecessary whitespace. The Storage SDK will fail to upload this because JavaScript can't perform it's native atob function - something the Firebase JS does under the hood. You'll have to strip the whitespace - see DOM Exception 5 INVALID CHARACTER error on valid base64 image string in javascript

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

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