作者:黑衬衫1994 | 来源:互联网 | 2023-02-02 10:11
我想通过监听由functions.database.ref().onWrite()
(而不是functions.storage.object().onChange()
)触发的事件来使用firebase云功能执行文件操作.
我注意到大多数使用云函数的示例functions.storage.object().onChange()
触发了用于文件操作的云函数.有没有办法storageRef
从内部获取functions.database.ref()
并执行文件操作?
1> Frank van Pu..:
要从数据库触发的云功能中访问Firebase存储,您可以使用Google Cloud SDK.
来自我的一个应用:
const gcs = require('@google-cloud/storage')();
...
exports
.emojifyStory = functions.database.ref('/stories/{storyId}')
.onWrite(function(event) {
const filePath = event.data.val().filePath;
const file = gcs.bucket(bucket).file(filePath);
// Use the Vision API to detect labels
return visionClient.detectLabels(file)
.then(data => {
...
@FrankvanPuffeken我使用Google Cloud SDK来理解这部分,只是无法弄清楚如何从Cloud Function获取`bucket`.现在很明显`bucket`只是`bucket = functions.config().firebase.storageBucket`.谢谢!