无法保存“自定义blob”到Firestore [英] Cannot save "custom blob" to Firestore

查看:80
本文介绍了无法保存“自定义blob”到Firestore的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在javascript中我从数组中创建一个blob:

In javascript I am creating a blob from an array like so:

const a = new Blob([[1,2,3]]);

当我尝试保存这个blob时:

when I try to save this blob like:

this.afs.collection('events').doc(event.getID()).set({data: new Blob([[1,2,3]])}).then((some) => {
      debugger;
    })

我收到错误:


使用无效数据调用DocumentReference.set()。不支持的字段值:自定义Blob对象(在字段数据中找到)

DocumentReference.set() called with invalid data. Unsupported field value: a custom Blob object (found in field data)

如何通过JS将blob保存到Firestore?

What should I do to save a blob via JS to Firestore?

推荐答案

您的blob必须是 firebase.firestore.Blob 。然后使用静态 fromUint8Array

Your blob needs to be of type firebase.firestore.Blob. Then using static fromUint8Array:

var firebase = require('firebase');
var app = firebase.initializeApp({ ... });
...
const blob = firebase.firestore.Blob.fromUint8Array(new Uint8Array([1,2,3]));

这篇关于无法保存“自定义blob”到Firestore的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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