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

395
Vistas
Downloading Image locally from GitHub Raw link using fs.writeFileSync() JS

Currently trying to download image from GitHub locally. Everything seems to work, the fetch goes through with a 200 OK response, however, I don't understand how to store image itself:

const rawGitLink = "https://raw.githubusercontent.com/cardano-foundation/CIPs/master/CIP-0001/CIP_Flow.png" 

const folder = "/Folder"
const imageName = "/Test"
const imageResponse = await axios.get(rawGitLink)


 fs.writeFileSync(___dirname + folder + imageName, imageResponse, (err) => {
   //Error handling                    
 }
)
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Four problems had to be fixed:

  • Image name must include png format for this case
  • The response must be in the correct format as a buffer for an image
  • You must write the response data and not the object itself
  • __dirname only needs two underscores
const rawGitLink = "https://raw.githubusercontent.com/cardano-foundation/CIPs/master/CIP-0001/CIP_Flow.png"

const folder = "/Folder"
const imageName = "/Test.png"
const imageResponse = await axios.get(rawGitLink, { responseType: 'arraybuffer' });

fs.writeFileSync(__dirname + folder + imageName, imageResponse.data)
about 4 years ago · Juan Pablo Isaza Denunciar

0

Axios returns a special object: https://github.com/axios/axios#response-schema

let {data} = await axios.get(...)
await fs.writeFile(filename, data) // you can use fs.promises instead of sync

As @Leau said you should include the extension on the filename Another sugestion is to use the path module to create the filename:

filename = path.join(__dirname, "/Folder", "Test.png")
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