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

269
Views
Nodejs - Fetch file from url and send content to client

For some reason, I don't want to share the URL public (sercet url),

My workflow is as below:

Client send API request to my server:

Api: mywebsite.com/api/image_abc.jpg

I have Nodejs express server to fetch the file from the url:

Eg: sercret_url.com/image_abc.jpg

And then from response image content from Nodejs, I send back the image content to the client and display as image_abc.jpg

I looked around on stackoverflow, but just got an answer from reading file from disk and send to client. What I want is just redirect the image content to client, not saving file to the disk.

Thank you.

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

0

Assuming you want to return the contents of a file from a certain URL to the client as buffer here's the solution I suggest

Get the file using axios and return the buffer to you client

  const axios = require('axios');
  let URL='some-valid-url'
  const response = await axios.get(
    URL,
    { responseType: 'arraybuffer' }
  );
  const buffer = Buffer.from(response.data, 'utf-8');
  res.status(200).send(buffer);

In case you want to save it to your server you can use fs as follows to write the file to the folder of your choice

  fs.writeFile(fileName, buffer, (err) => {
      if(!err) console.log('Data written');
    });
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!