0

I was trying to get the Image URL token from firebase storage. I was able to generate the full URL of the image stored in firebase storage but without that token, I can not access it.

I am using Nodejs v16.

fullURL = https://firebasestorage.googleapis.com/v0/b/first-project-17ec7.appspot.com/o/lp.png

const storage = require("firebase/storage");

let storageRef = await storage.ref(fullURL);
storageRef.getDownloadURL().then(function(url) {
   console.log(url);
});

Output:

error :  TypeError: storageRef.getDownloadURL is not a function
at download (/Users/turinganalytics/Development/transform/src/utils/download.js:51:16)
at async Object.getBuffer (/Users/turinganalytics/Development/transform/src/utils/origin.js:315:30)

Expected Output: https://firebasestorage.googleapis.com/v0/b/first-project-17ec7.appspot.com/o/lp.png?alt=media&token=6d3766fd-b043-4252-8783-b1f7f260d5fd

There are no set of rules in the firebase console.

rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write: if request.auth != null;
    }
  }
}

Is there any node js library for firebase that I can retrieve that unique token.?

Keval
  • 85
  • 8
  • What is your Firebase version ? – Dharmaraj Nov 08 '21 at 09:19
  • I am using firebase 9.3.0 – Keval Nov 08 '21 at 09:46
  • You are using the new Modular SDK which has a new syntax. Have you checked out [documentation](https://firebase.google.com/docs/storage/web/download-files) for the same? – Dharmaraj Nov 08 '21 at 09:50
  • Yes. but it gives me FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app). So What I want is that I am not the owner of the firebase storage. I am taking the app name and base URL as input for accessing the full URL of the image. but I can't able to generate an access token. – Keval Nov 08 '21 at 10:17
  • 1
    The Firebase Admin SDK for Node.js is a thin wrapper around the GCP Node.js SDK, and doesn't have a `getDownloadURL()` method. To generate download URLs, have a look at this answer: https://stackoverflow.com/a/43764656. – Frank van Puffelen Nov 08 '21 at 15:39

0 Answers0