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

150
Views
Why is my downloaded file corrupted in Javascript?

I am trying to download a file from my nodeJS server, however opening the files afterwards is not possible. For example: The original 15kb JPG file will be 24kb when downloaded and impossible to show.

upload:

        if (fs.existsSync(filePath)) {
            res.download(filePath);
            readStream.pipe(res);
        } else {
            return res.status(404).json({msg: "Failed to load file"});
        }

download:

import fileDownload from "js-file-download";

    const getFile = async (filename) => {
        const headers = {
            'responseType': 'blob',
            'x-access-token': JSON.parse(localStorage.getItem('user')).token
        }

        await axios.post(getFileRoute, {
                filename: filename
            }, {headers: headers})
                .then((response) => {
                    fileDownload(response.data, filename);
                });
            }

The picture preview is also shown in the network tab of google chrome's inspect. Thank you for your help!

about 4 years ago · Juan Pablo Isaza
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!