【发布时间】:2018-04-22 21:29:53
【问题描述】:
我一直在成功使用 Firebase 函数对我上传到 Firebase 存储的文件执行操作。
我目前想要做的是使用通配符访问我将数据推送到其中的文件夹,其实现方法与实时数据库 + Firestore 的工作方式相同。但是,每当我尝试访问这些参数时,它们都会专门返回 null。
这不可能吗?
这是我的代码示例:
exports.generateThumbnail = functions.storage.object('user-photos/{userId}/{publicOrPrivate}').onChange(event => {
const privateOrPublic = event.params.publicOrPrivate;
const isPrivate = (event.params.publicOrPrivate == "private");
const userId = event.params.userId;
console.log("user id and publicOrPrivate are", userId, privateOrPublic);
//"user id and publicOrPrivate are undefined undefined"
}
谢谢!
【问题讨论】:
-
基于this documentation,可以从事件中获取bucket中的完整文件路径:
event.object.name。然后,您需要提取所需的路径段。你试过吗? -
谢谢,但我有。我希望有一种更优雅的方式来做到这一点。我不喜欢将字符串解析成数组,感觉有点 hacky :
标签: node.js firebase firebase-storage google-cloud-functions