如何从数据库触发的 Cloud Functions 中访问 Firebase 存储?
How do I access Firebase storage from within a Database-triggered Cloud Function?
我想通过侦听由 functions.database.ref().onWrite()
(而不是 functions.storage.object().onChange()
)触发的事件来使用 firebase 云函数执行文件操作。
我注意到大部分示例使用云函数 functions.storage.object().onChange()
来触发云函数来进行文件操作。有没有办法从 functions.database.ref()
中获取 storageRef
并从那里执行文件操作?
要从您的数据库触发 Cloud Function 访问 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 => {
...
我想通过侦听由 functions.database.ref().onWrite()
(而不是 functions.storage.object().onChange()
)触发的事件来使用 firebase 云函数执行文件操作。
我注意到大部分示例使用云函数 functions.storage.object().onChange()
来触发云函数来进行文件操作。有没有办法从 functions.database.ref()
中获取 storageRef
并从那里执行文件操作?
要从您的数据库触发 Cloud Function 访问 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 => {
...