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

396
Views
Descarga de la imagen localmente desde el enlace GitHub Raw usando fs.writeFileSync() JS

Actualmente intento descargar la imagen de GitHub localmente. Todo parece funcionar, la búsqueda se realiza con una respuesta de 200 OK , sin embargo, no entiendo cómo almacenar la imagen en sí:

 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 answers
Answer question

0

Había que solucionar cuatro problemas:

  • El nombre de la imagen debe incluir el formato png para este caso
  • La respuesta debe estar en el formato correcto como un búfer para una imagen
  • Debe escribir los datos de respuesta y no el objeto en sí
  • __dirname solo necesita dos guiones bajos
 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 Report

0

Axios devuelve un objeto especial: 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

Como dijo @Leau, debe incluir la extensión en el nombre del archivo. Otra sugerencia es usar el módulo de path para crear el nombre del archivo:

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