Google Cloud Keyfile.json #219
Replies: 6 comments 11 replies
-
This works for me: My |
Beta Was this translation helpful? Give feedback.
-
It is bad practice to put keys in the deployed repo. How is your json file getting into the project folder? |
Beta Was this translation helpful? Give feedback.
-
I had the exact same issue some weeks ago but luckily there's a pretty easy workaround: const credential = JSON.parse(
Buffer.from(process.env.GOOGLE_SERVICE_KEY, "base64").toString()
);
const visionClient = new vision.v1.ImageAnnotatorClient({
projectId: "my-project-id",
// important
credentials: {
client_email: credential.client_email,
private_key: credential.private_key,
},
}); The important part is that you need to base64 encode your google service account key. Take this as a reference: https://cloud.google.com/iam/docs/creating-managing-service-account-keys Then you need to add this key to your .env.local file in the form of GOOGLE_SERVICE_KEY=base64_encoded_key Instead of a keyfile you basically save the file's content as an env var, then inside your code you decode the base64 string and parse it to an actual json object which you can then use to authenticate. The google API documentation is not that good when it comes to examples like this. |
Beta Was this translation helpful? Give feedback.
-
Hey folks, good news. We've made handling private keys much easier in two main ways: |
Beta Was this translation helpful? Give feedback.
-
Do this import { Storage } from "@google-cloud/storage"; const storage = new Storage({ |
Beta Was this translation helpful? Give feedback.
-
With Google Cloud's Application Default Credentials, some API's are looking for a json file. |
Beta Was this translation helpful? Give feedback.
-
I am trying to authenticate with Google Cloud via a Next API route.
GCP needs the path to the key JSON file. Not the values in the file, but the actual file.
So links to tutorials re: base64 and secrets etc. won’t work. (I don’t think)
GCP - API
const client = new vision.v1.ImageAnnotatorClient({ projectId, keyFilename });
keyFilename = path to actual keyfile.JSON.
I can’t make this work once deployed. Locally … no prob.
My workaround is to host my GCP vision function on Google cloud. Would like to get all on to Vercel.
Any thoughts? LMK if i am way off base and I just don't know what I am doing.
I think this is a similar issue
vercel/next.js#13624
I have tried - let keyFilename = path.resolve("./keyfile.json");
Again works locally.
Thanks
Cole
Beta Was this translation helpful? Give feedback.
All reactions