0

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.
Deji James
  • 367
  • 6
  • 20
  • `getDownloadURL()` does not exist in the Node.js SDK. See https://stackoverflow.com/questions/42956250/get-download-url-from-file-uploaded-with-cloud-functions-for-firebase, which has both a way to generate a download URL there by setting metadata yourself, and the more common alternative in Node.js which are called signed URLs. – Frank van Puffelen Jun 23 '21 at 02:22
  • Hi @FrankvanPuffelen thanks for the clarification. My issue is that I followed the instructions of the answer and I am getting another error. I have edited my question to reflect this. I noted a few others have had this issue. – Deji James Jun 23 '21 at 04:36
  • That looks like a new problem. I recommend opening a new question, so that others are also more likely to see it. – Frank van Puffelen Jun 23 '21 at 13:20

0 Answers0