1

I'm having issues generating external links to files stored in my Firebase Storage bucket.

I'm using Google Cloud Storage for a while now and used this library (which is based on this answer) for generating external links for regular Storage buckets, but using it on the Firebase-assigned bucket doesn't seem to work.

I can't generate any secure HTTPS links and keep getting certificate validation error NET::ERR_CERT_COMMON_NAME_INVALID stating that my connection is not private. If I remove the 'S' from the HTTPS, the link works.

NOTE: Using the same credentials and private key to generate links for other buckets in my project, works just fine. It's only the Firebase bucket that is refusing to accept my signing...

Community
  • 1
  • 1
Aralizer
  • 185
  • 2
  • 15

1 Answers1

4

I recommend using the official GCloud client, and then you can use getSignedUrl() to get a download URL to the file, like so:

bucket.file(filename).getSignedUrl({
  action: 'read',
  expires: '03-17-2025'
}, function(err, url) {
  if (err) {
    console.error(err);
    return;
  }

  // The file is now available to read from this URL.
  request(url, function(err, resp) {
    // resp.statusCode = 200
  });
});

Per Generate Download URL After Successful Upload this seems to work with Firebase and GCS buckets.

Community
  • 1
  • 1
Mike McDonald
  • 15,609
  • 2
  • 46
  • 49
  • Didn't know the official Gcloud supported that, thanks! – Aralizer Jun 17 '16 at 12:55
  • I'm getting a "Caller does not have storage.objects.get access to object" error with this code. Any idea why? – doovers Oct 28 '16 at 17:48
  • Have you created a service account (https://cloud.google.com/storage/docs/authentication#service_accounts) with the correct permissions? The objects themselves may not have the correct permission with that service account, so you'll need to add them the the default object ACL and to any existing objects (`gsutil -m acl ch -r -u @system.gserviceaccount.com:O gs://`) – Mike McDonald Oct 31 '16 at 03:33
  • New project's name is `@google-cloud/storage` and Bucket method `getSignedUrl` does not exist anymore. – Matt Jensen Jan 14 '19 at 22:34