I would like to perform file manipulation using firebase cloud functions by listening to an event triggered by functions.database.ref().onWrite()
(instead of functions.storage.object().onChange()
).
I noticed most of the sample using cloud functions functions.storage.object().onChange()
to trigger a cloud functions for file manipulation. Is there a way to get a storageRef
from within functions.database.ref()
and perform file manipulation from there?
To review your Cloud Storage billed usage, check the Usage and Billing dashboard. For resource usage, both the Cloud Storage Usage tab in the Firebase console and the metrics available through Cloud Monitoring can help you monitor Cloud Storage usage.
Implementation path. Install the Firebase CLI and initialize Cloud Functions in your Firebase project. Write JavaScript code (or TypeScript code to transpile at deployment) to handle events from Firebase services, Google Cloud services, or other event providers. Use the local emulator to test your functions.
To access Firebase Storage from within your database triggered Cloud Function, you can use the Google Cloud SDK.
From one of my apps:
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 => {
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With