I’m trying to get the default bucket in Firebase from a function. It appears there was recently a change in the SDK and I can’t find information on retrieving it anymore. I’ve tried a million things my current code looks like this and returns an empty string.
import * as admin from "firebase-admin";
import * as functions from "firebase-functions";
admin.initializeApp({
credential: admin.credential.applicationDefault(),
});
export const processVideo = functions.https.onCall(async (data, context) => {
const bucket = admin.storage().bucket.name;
functions.logger.log("***************Bucket Name****************", bucket);
});
2
Answers
It turns out that the information is stored in an environment variable but not imported into the admin tooling directly. So the best way I have found to prepare your environment to serve the default bucket name is as follows:
The documentation suggests that you’re supposed to provide that value to the SDK when you initialize it. The SDK doesn’t just know it without being told.
So, you have to get the value from the Firebase console and use that to initialize the SDK.
Also, you need to use a method called
bucket()
, not a property. The API documentation says it returns a Bucket object.