1
votes

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

1
Please edit your question to explain what it is you're observing that indicates you haven't set this up correctly. Is there an error message when running the code?Doug Stevenson
thank you very much @DougStevenson , I have edited the question.Agung Laksana
oh my God, newbie mistake, should be ./service-account.json instead of ../service-account.json . case closedAgung Laksana
Feel free to answer your own question and mark it as accepted after enough time passes for SO to allow it.Doug Stevenson
Hello Agung. What is the environment of this image? I should put service-account.json inside src folder and the link is here:github.com/android/play-billing-samples/tree/master/… I would appreciate if you tell me what I should do. which software? Or what should I do with those files in the link.Namikaze Minato

1 Answers

-1
votes

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