gpt4 book ai didi

javascript - 无法将 "custom blob"保存到 Firestore

转载 作者:行者123 更新时间:2023-11-30 09:18:04 26 4
gpt4 key购买 nike

在 javascript 中,我从数组创建一个 blob,如下所示:

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

当我尝试保存这个 blob 时,例如:

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

我收到错误:

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

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

最佳答案

您的 blob 类型必须为 firebase.firestore.Blob 。然后使用静态fromUint8Array:

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

关于javascript - 无法将 "custom blob"保存到 Firestore,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53671952/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com