【发布时间】:2019-05-22 23:34:17
【问题描述】:
跟进我已经完成的一个较早的问题here 现在我在管理 SDK 上遇到了同样的问题,但无法解决这个问题。
我正在尝试将 blob 保存到 Firestore,但我得到:
Error: Value for argument "data" is not a valid Firestore document. Couldn't serialize object of type "Blob" (found in field data). Firestore doesn't support JavaScript objects with custom prototypes (i.e. objects that were created via the "new" operator).
以下是我将自定义 Blob 转换为 Firestore Blob 的方法:
// The import
import {firestore} from "firebase";
// The function
export const parseQueue = functions.region('europe-west2').pubsub.schedule('every 1 minutes').onRun(async (context) => {
....code...
// The problem
writePromises.push(
admin.firestore()
.collection('users')
.doc(userID)
.collection('events')
.doc(<string>event.getID())
.collection('activities')
.doc(<string>activity.getID())
.collection('streams')
.doc(stream.type)
.set({
type: stream.type,
data: firestore.Blob.fromBase64String(new Buffer((Pako.gzip(JSON.stringify(stream.data), {to: 'string'})), 'binary').toString('base64')),
}))
当我使用前面提到的错误调用 set 时,上述崩溃。
firestore.Blob.fromBase64String 函数运行良好,我确实得到了一个很好的 blob。
我做错了什么?
【问题讨论】:
标签: javascript node.js firebase google-cloud-firestore blob