0

In a Firebase Function, I am retrieving newly created objects from Firebase Storage as follows. the operation works, but in production environments I get the Google Storage URL (Not Publicly Accessible) instead of Firebase Storage URL (Publicly Accessible)

exports.myFunc = functions.storage.object().onFinalize(async (object) => {
    // the following prints 
    // https://storage.googleapis.com/download/storage/v1/b/<bucket>/o/<filename>?generation=<generation>&alt=media (not publicly accessible) 
    // instead of 
    // https://firebasestorage.googleapis.com/v0/b/<bucket>/o/<filename>?alt=media&token=<token> (publicly accessible)
    console.log(object.mediaLink) 
}

I am expecting to see the https://firebasestorage.googleapis.com... URL since this is the one that works for public access. is this a known bug or do I need to do something else in order to retrieve the public URL?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
kob490
  • 3,177
  • 4
  • 25
  • 40
  • That is expected: since the object comes directly from Cloud Storage, it doesn't have any Firebase download URL in it, and the Admin SDKs for Cloud Storage don't have method to generate a Firebase download URL either. For your options, see the top 2 answers of https://stackoverflow.com/questions/42956250/get-download-url-from-file-uploaded-with-cloud-functions-for-firebase – Frank van Puffelen Nov 06 '22 at 22:26
  • isn't that an issue though? in the Firebase storage dashboard the URL for that file is generated as the "firebasestorage.googleapis.com" one. why is the discrepancy? – kob490 Nov 06 '22 at 23:18
  • The post I linked shows two equally workable ways to get a sharable URL - one of which has the same domain. Being able to do so with a call in the Admin SDK *is* a valid feature request though, so if you want: [file a feature request](https://firebase.google.com/support/troubleshooter/report) – Frank van Puffelen Nov 07 '22 at 01:49

0 Answers0