Open royibernthal opened 6 months ago
@royibernthal Well actually,
GOOGLE_APPLICATION_CREDENTIALS
should be a path
of your private credentials key in JSON format
and that should be stored in the GLOBAL ENVIRONMENT
of the system.
That's what exactly what I did :)
Did you add the variable like this? https://www3.ntu.edu.sg/home/ehchua/programming/howto/Environment_Variables.html
and restarted the server?
And also if you have done that, there is no need to import it using process.env it will automatically be imported
I'm using dotenv locally and injecting env vars to the container on aws in production. At the end of the day process.env holds the env vars of the running nodejs process, does it really matter how they got there? Even setting them manually should do the trick no?
Notice that the normal recognize does use the credentials in the env vars properly (path that leads to the file that contains the credentials), and only the second line in long recognize doesn't.
Hm, could you try running:
gcloud auth application-default login
? Still weird that one authentication method works for one and not the other.
loosely related, but searching online and not seeing any ways to initialize Google Cloud without keyFileName - which isn't ideal for production cloud environments. JSON file is fine for local development, but what is the expectation for hosting service account in the cloud?
and even though in the documentation it says you can initialize via javascript object, i'm getting errors when trying to pass credentials directly in via environment variables like below. it seems the Cloud Storage environment automatically checks for process.env.GOOGLE_APPLICATION_CREDENTIALS which doesn't exist when passing in via js object. unsure if thats a bug or if passing in via js object is not the right approach.
any feedback would be appreciated!
const gCloudStorage = new Storage({
projectId: `project id`,
credentials: {
// credentials loaded via .env variables
}
})
i've also tried to pass the json directly into my .env variable, like below, and then parsing the JSON like this in my app. but that gives me a ENAMETOOLONG error. i guess it thinks the json body is the file name???
.env file
GOOGLE_APPLICATION_CREDENTIALS=service-acct-json-body
when accessing storage
const gCloudStorage = new Storage({
projectId: 'project-id',
credentials: JSON.parse(
process.env.GOOGLE_APPLICATION_CREDENTIALS.replace(/\n/g,"")
)
})
Environment details
Steps to reproduce
I'm using Google Cloud Speech To Text in NodeJS.
I specified the correct path to the google cloud credentials in process.env.GOOGLE_APPLICATION_CREDENTIALS.
The normal recognize works as expected:
However, the long running recognize throws an error:
The second line throws the following error: