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(<any>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;
}
Thanks @Doug Stevenson. I believe I found an answer.
I solve deployment errors by recreating new project.
I change my initialization to code below to solve unhandled rejection. Go to Service Acccounts under Project Settings in your firebase project and generate new private key under firebase admin sdk.
const serviceAccount = require('./path/to/serviceaccount.json');
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: '<ur database url>', // check it under service accounts
storageBucket: '<ur storage bucket url>' //check it in script snippet require to add to your website.
});