7

Inside a cloud function, how can I get the download-url of a storage file?

const functions = require('firebase-functions');
const admin = require('firebase-admin');

admin.initializeApp(functions.config().firebase);
const storage = admin.storage();

Using this storage object I can do storage.bucket().file(path).getMetadata() but the returned metadata does not contain the firebase-signed-download-url.

The docs says to create a reference and do reference.getDownloadURL(). Only thing is that this does not seem to work with the storage object returned from the firebase-admin package.

yN.
  • 1,847
  • 5
  • 30
  • 47
  • 1
    The question that this is allegedly a duplicate of was asked/answered before firebase-admin was able to access Firebase Storage. The current solution is similar, but you can use `admin.storage().bucket()` to create a bucket rather than requiring `@google-cloud/storage`. – Sidney Mar 13 '18 at 19:13
  • 1
    In other words, OP, you were very close, but you should have used `.getSignedUrl()` rather than `.getMetadata()`. – Sidney Mar 13 '18 at 19:14
  • @Sidney The firebase-admin module just provides a thin wrapper on top of @google-cloud/storage. It doesn't do anything different, in practice. – Doug Stevenson Feb 14 '21 at 07:58

0 Answers0