My goal is to fetch the download URL for newly uploaded files in order to store it in my database. I've tried following guidance from both this answer and the official documentation, but I keep encountering errors within my function.
Below are the packages I have imported:
import * as functions from "firebase-functions";
import * as admin from "firebase-admin";
import { FieldValue } from "@google-cloud/firestore";
import { _namespaceWithOptions } from "firebase-functions/lib/providers/firestore";
admin.initializeApp(functions.config().firebase);
const db = admin.firestore();
const defaultStorage = admin.storage();
This is how my cloud function currently looks:
exports.writeFileToDatabase = functions.storage
.object()
.onFinalize(object => {
const bucket = defaultStorage.bucket();
const file = bucket.file(object.name as string);
const options = {
action: 'read',
expires: '03-17-2025'
};
return file.getSignedUrl(options)
.then(results => {
const url = results[0];
console.log(`The signed url is ${url}.`);
return true;
})
});
However, when passing options
into getSignedUrl
, I receive this error:
Argument of type '{ action: string; expires: string; }' is not assignable to parameter of type 'GetSignedUrlConfig'
I also encounter an error regarding results
, stating:
Parameter 'results' implicitly has an 'any' type
Despite referencing examples, I am unable to spot the differences causing these issues.