Get shorter file url from google cloud storage (with Firebase cloud features)

I have the following Firebase cloud function to get the url of a file stored in google cloud storage.

const gcs = require('@google-cloud/storage')({keyFilename: 'service-account.json'});

exports.generateFileLink = functions.storage.object().onChange(event => {
  const object = event.data;
  const filePath = object.name;
  const bucket = gcs.bucket(object.bucket);
  const file = bucket.file(filePath);
  const action = 'read';
  const expires = '03-09-2491';
  return file.getSignedUrl({action, expires}).then(signedUrls => {
    console.log(signedUrls[0])
  });
})

      

Returns the correct URL, but it is more than 600 characters long. The url for the same file as seen in the Firebase web console is less than 200 characters. Is there a way to get the url using firebase-admin modules or firebase functions to get a shorter url?

+3


source to share


1 answer


The short answer is that we are working on the firebase-admin

Storage client , but still not much. For now, signed urls are the way to go if you need to create a download url in a function.



Why would you need to create signed urls in vs function using download urls provided by Firebase? Can't you get the url through the client in this function and you need to move it somewhere else?

+3


source







All Articles