Agung
Agung

Reputation: 13843

how to get service-account.json to get signedURL in Firebase?

I try to follow the answer in here Get Download URL from file uploaded with Cloud Functions for Firebase . to get the download URL for my image stored in Firebase storage

but i need to get service-account.json keyFilename when initializing gcs for the code below

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

I don't know how to set up {keyFilename: 'service-account.json'} correctly.but here is what I've done:

  1. first, I generate the private key from here and name it as service-account.json https://console.firebase.google.com/project/yourprojectID/settings/serviceaccounts/adminsdk , the service-account.json contains information like this:

    { "type": "service_account", "project_id": "", "private_key_id": "", "private_key": , "client_email": "", "client_id": "", "auth_uri": "", "token_uri": "", "auth_provider_x509_cert_url": "", "client_x509_cert_url": "" }

  2. and then place the file in the function folder and use it like the picture below:

enter image description here

but I get error from cloud function log:

{ Error: ENOENT: no such file or directory, open '../service-account.json'
    at Error (native)
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '../service-account.json' }

the gcs is actually used to generate thumbnail whenevet I upload an image to the storage using the code from here: https://github.com/firebase/functions-samples/blob/master/quickstarts/thumbnails/functions/index.js

Upvotes: 0

Views: 2725

Answers (1)

Agung
Agung

Reputation: 13843

newbie mistake, should be ./service-account.json instead of ../service-account.json

Upvotes: -1

Related Questions