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

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

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 Report

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 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!