1

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

Agung Laksana
  • 781
  • 1
  • 12
  • 26
  • 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 Sep 11 '18 at 23:15
  • thank you very much @DougStevenson , I have edited the question. – Agung Laksana Sep 11 '18 at 23:30
  • oh my God, newbie mistake, should be ./service-account.json instead of ../service-account.json . case closed – Agung Laksana Sep 11 '18 at 23:35
  • Feel free to answer your own question and mark it as accepted after enough time passes for SO to allow it. – Doug Stevenson Sep 11 '18 at 23:56
  • Hello Agung. What is the environment of this image? I should put service-account.json inside src folder and the link is here:https://github.com/android/play-billing-samples/tree/master/ClassyTaxiServer 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 Apr 17 '20 at 07:31

1 Answers1

-1

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

Agung Laksana
  • 781
  • 1
  • 12
  • 26