I am trying to retrieve the download url for new files uploaded so I can write that to my db. I've followed both this answer and the official docs but I am getting errors in my function.
These are my imports:
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 currently my desired cloud function:
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;
})
});
But when passing options
into getSignedUrl
I get this error:
Argument of type '{ action: string; expires: string; }' is not assignable to parameter of type 'GetSignedUrlConfig'
Also I get an error on results
saying:
Parameter 'results' implicitly has an 'any' type
I can't see what I am doing different form the examples I've used as reference.