Ad
Access Firebase Storage From Firebase Functions
My ultimate target is to generate a pdf and send it via email through Firebase Cloud Function but I'm still testing things out. I am sending emails using Nodemailer. My next step is to include an image I have store in the same project on Firebase Storage.
How can I access the files I have in Storage to include as an attachment? My trigger for the function is onCreate()
for a node in RTDB.
functions.database
.ref("/jobs/draft/{id}")
.onCreate((snapshot: any, context: any) => {
Ad
Answer
To "access the files you have in Storage" you have to use the Admin SDK, as follows:
//.....
const admin = require('firebase-admin');
//.....
functions.database
.ref("/jobs/draft/{id}")
.onCreate((snapshot: any, context: any) => {
const fileBucket = 'gs://bucket.appspot.com';
const filePath = 'path/to/file';
const bucket = admin.storage().bucket(fileBucket);
const file = bucket.file(filePath);
//.....
});
See also https://googleapis.dev/nodejs/storage/latest/Storage.html
Ad
source: stackoverflow.com
Related Questions
- → How can I query Firebase for an equalTo boolean parameter?
- → How can I access nested data in Firebase with React?
- → Firebase simple blog (confused with security rules)
- → Removing item in Firebase with React, re-render returns item undefined
- → AngularJS Unknown Provider Error (Firebase & AngularFire)
- → How do you pass top level component state down to Routes using react-router?
- → "this" is null in firebase query function in reactjs
- → Angular Module Failed to Load
- → Multiple dex files define Lcom/google/android/gms/internal/zzrx;
- → Joining Firebase tables in React
- → How can I make add firepad to my reactjs project?
- → How to use Cloud Functions for Firebase to prerender pages for SEO?
- → React.js component has null state?
Ad