On my firebase callable cloud function, I can currently generate a document and upload it successfully to the firebase cloud storage. My issue now is how to get the url from the successfully uploaded file (with the access token) back to the client side. This is currently what I have but I keep getting an error message:
/{.......}/
const contentBuffer = doc.getZip().generate({ type: "nodebuffer" });
// reupload to Cloud Storage
const targetStorageRef = admin.storage().bucket().file("output.docx");
await targetStorageRef.save(contentBuffer);
// send back a URL and the bucket-name pair to the caller
const location = await targetStorageRef.getDownloadURL();
return { url: location, bucket: targetStorageRef.bucket.name, name: "output.docx" };
The error message I keep getting is :Unhandled error TypeError: targetStorageRef.getDownloadURL is not a function
Is there a way that the url of the "output.docx" can be returned to the client side?
UPDATE
I updated my require list to follow the firebase documentation as follows:
const admin = require('firebase-admin');
const {Storage} = require('@google-cloud/storage');
var serviceAccount = require("/Users/johndoe/Downloads/myapp-firebase-adminsdk-1234-567.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
storageBucket: "myapp.appspot.com"
});
My issue is that when I try to deploy the function to firebase I get the error:
To try redeploying those functions, run:
firebase deploy --only "functions:test"
To continue deploying other features (such as database), run:
firebase deploy --except functions
Error: Functions did not deploy properly.