Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

582
Views
TypeError: la clave debe ser una cadena, un búfer o un objeto en typeError con archivo GCP existe

Simplemente estoy tratando de probar la existencia de un archivo en nuestro almacenamiento de Google Cloud Platform (GCP). Estoy usando cubos de GCP en servidores express js. A continuación se muestra esencialmente un ejemplo muy simple copiado de https://googleapis.dev/nodejs/storage/latest/File.html#exists

EDITAR: Así es como autentico la clave GCP:

 const { Storage } = require('@google-cloud/storage'); const storage = new Storage({ projectId: 'my-cloud', keyFilename: process.env.GOOGLE_APPLICATION_CREDENTIALS, }); const bucketName = 'my-ci';

(Con pequeños cambios, me doy cuenta de que se supone que debe devolver data[0] )

 const bucket = storage.bucket(bucketName); const file = bucket.file(path); const exists = await file.exists().then(data => { return data })

Pero cuando intento ejecutar esto, aparece el error:

 [nodemon] starting `node --inspect server/server.js` Debugger listening on ws://127.0.0.1:9229/9a677766-4a93-4499-b57c-55f5f05096d7 For help, see: https://nodejs.org/en/docs/inspector Server listening on port 4000! /opt/node_modules/jwa/index.js:115 return new TypeError(errMsg); ^ TypeError: key must be a string, a buffer or an object at typeError (/opt/node_modules/jwa/index.js:115:10) at checkIsPrivateKey (/opt/node_modules/jwa/index.js:61:9) at Object.sign (/opt/node_modules/jwa/index.js:147:5) at Object.jwsSign [as sign] (/opt/node_modules/jws/lib/sign-stream.js:32:24) at JWTAccess.getRequestHeaders (/opt/node_modules/google-auth-library/build/src/auth/jwtaccess.js:87:31) at JWT.getRequestMetadataAsync (/opt/node_modules/google-auth-library/build/src/auth/jwtclient.js:76:51) at JWT.getRequestHeaders (/opt/node_modules/google-auth-library/build/src/auth/oauth2client.js:238:37) at GoogleAuth.authorizeRequest (/opt/node_modules/google-auth-library/build/src/auth/googleauth.js:593:38) at processTicksAndRejections (node:internal/process/task_queues:96:5)

Dado que el mensaje de error no proporcionó un rastreo útil, investigué un poco por mi cuenta. Al poner declaraciones de console.log en todas partes, lo reduje a la línea

 const exists = await file.exists().then(data => { return data })

y probé varios enfoques, desde eliminar la .then(...) hasta eliminar la await (que funciona hasta que se resuelve la promesa). Ninguno de estos parecía haber funcionado.

¿Cuáles pueden ser las posibles causas de esto?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Finalmente lo descubrí: se debió a que la clave GCP era una versión anterior de la clave. Si obtiene un error como el anterior, intente verificar que su clave sea correcta.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!