I\'m having problem getting download url in firebase function after saving image to cloud storage. Below is my firebase http function in typescript to save base64 string to
You're not showing all the code here (for example, how you initialized the Firebase Admin SDK to create admin
). So I'm going to assume that you used the project default credentials to initialize it like this:
import * as admin from 'firebase-admin'
admin.initializeApp()
This isn't sufficient to to be able to use getSignedUrl when reaching into the admin SDK to use Cloud Storage APIs. If you want to use getSignedUrl, you'll need to provide the credentials for a dedicated service account that you create in the console.
Assuming that you put those credentials in a file called yourServiceAccount.json in your functions folder, you should initialize the admin SDK with those credentials like this:
import * as serviceAccount from 'yourServiceAccount.json';
const adminConfig = JSON.parse(process.env.FIREBASE_CONFIG)
adminConfig.credential = admin.credential.cert(serviceAccount)
admin.initializeApp(adminConfig);
Note that this is just taking the default project config from FIREBASE_CONFIG and adding the service account to them.
In order to get the import of a JSON file, you will also need to have a file (called typings.d.ts):
declare module "*.json" {
const value: any;
export default value;
}