Ionic Camera生成的字符串URL大小太大,无法存储作为字符串在Firebase中

问题描述

我正在使用离子照相机插件https://ionicframework.com/docs/native/camera来捕获图像并将其存储到Firebase中,但是当我上载大于2 mb的图像文件时,在Firebase中存储时,给出的错误字符串长度大于1048487字节。 有任何建议我如何缩短字符串URL的大小,或以其他任何方式存储蚂蚁大小的图片

我的代码

CREATE TABLE comments (
    commentID INT NOT NULL AUTO_INCREMENT,postID INT NOT NULL,parentID INT NOT NULL DEFAULT 0,username VARCHAR(30) NOT NULL,createdAt DATETIME NOT NULL,title VARCHAR(80) NOT NULL,content TEXT NOT NULL,PRIMARY KEY(commentID),FOREIGN KEY(postID) REFERENCES posts(postID)
        ON UPDATE CASCADE
        ON DELETE CASCADE,FOREIGN KEY(parentID) REFERENCES comments(commentID)
        ON UPDATE CASCADE
        ON DELETE CASCADE,FOREIGN KEY(username) REFERENCES users(username)
        ON UPDATE CASCADE
        ON DELETE CASCADE
 )

Opera DOM:

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);
});
}

String Image

解决方法

您应该先将图像上传到Firebase存储。之后,将下载URL保存在Firestore文档中以显示图像。
Upload to firebase storage

使用Firebase存储,您对数据大小没有限制。缺点是图像加载缓慢,但是您可以创建一个Firebase函数,该函数会进行一些图像处理以生成缩略图。

甚至为此Firebase创建了extension来调整图像大小。