无法保存“自定义 blob"到 Firestore [英] Cannot save "custom blob" to Firestore
本文介绍了无法保存“自定义 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屋!
查看全文