ionic-framework - Ionic Camera 生成的字符串 URL 太大而无法在 Firebase 中存储(作为字符串)
问题描述
我正在使用离子相机插件https://ionicframework.com/docs/native/camera来捕获图像并存储到 Firebase 中,但是当我上传大小大于 2 mb 的图像文件时,同时存储在 Firebase 中它会给字符串长度超过 1048487 字节的错误。任何建议我如何缩短字符串 URL 大小或任何其他存储任何蚂蚁大小图片的方式。
我的代码:
takePicture()
{
const options: CameraOptions = {
quality: 30,
destinationType: this.camera.DestinationType.DATA_URL,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE,
allowEdit: true,
sourceType: 1,
saveToPhotoAlbum: false,
};
this.camera.getPicture(options).then((imageData) => {
this.cardopen = !this.cardopen;
this.takephoto = 'data:image/jpeg;base64,' + imageData;
console.log(this.takephoto);
}, (err) => {
console.log(err);
});
}
歌剧 DOM:
core.js:4197 ERROR Error: Uncaught (in promise): FirebaseError: [code=invalid-argument]: The value of
property "ImageUrl" is longer than 1048487 bytes.
FirebaseError: The value of property "ImageUrl" is longer than 1048487 bytes.
解决方案
您应该先将图像上传到 Firebase 存储。之后,您将下载 url 保存在您的 firestore 文档中以显示图像。
上传到 Firebase 存储
使用 Firebase 存储,您对数据大小没有限制。缺点是图像加载缓慢,但您可以创建一个 firebase 函数来执行一些图像处理以生成缩略图。
即使为这个 firebase 创建了一个扩展来调整图像大小。
推荐阅读
- apache-kafka - 我收到一个错误 Kafka Connect HDFS 连接器并且没有数据写入 HDFS
- gosu - TextInput 框旁边的示例文本
- android - 如何使用 RecyclerView 项填充 AlertDialog
- xml - 处理 XML 文本内容而不包含标记标签
- windows - 无法定义具有重复名称“DoBenchmark”的奇怪函数,因为该函数仅在一个地方定义
- sql - 具有多个文件的一个字段映射:MsAccess SQL
- python - 使用 Pandas 检查 Python 中的日期列表是否完整
- eloquent - 缺少的数据属于许多关系
- go - Prometheus 警报管理器模板更改
- java - 我的 ObjectOutputStream 工作不正常