Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

290
Vistas
How do I send a YAML file as a base64 encoded string?

I am trying to send a yaml file as a base64 string so that this code works:

const response = await octokit.request('GET /repos/{owner}/{repo}/git/blobs/{file_sha}', {
  owner: 'DevEx',
  repo: 'hpdev-content',
  file_sha: fileSha,
  headers: {
    authorization: `Bearer ${githubConfig?.token}`,
  },
});

const decoded = Buffer.from(response.data.content, 'base64').toString('utf8');

In the above code response.data.content should have the data.

I have this route:

router.get('/repos/:owner/:repo/git/blobs/:file_sha', (req, res) => {
    // TODO: do we need to do anything with the path params?
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
    const { owner, repo, file_sha } = req.params;

    const contents = writeUsersReport();
    const encoded = Buffer.from(contents, 'binary').toString('base64');

    res.send(encoded);
});

The code is working fine except that the client code expects the base64 string in a property called content in the following code:

const decoded = Buffer.from(response.data.content, 'base64').toString('utf8');

But the string is in response.data. How can I set the content property instead?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

How about sending a json response containing an object with a content property from your server side instead of the encoded string directly?

// ...
const encoded = Buffer.from(contents, 'binary').toString('base64');
res.json({content:encoded});
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda