Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

83
Views
How do I handle res.download(pathname) on frontend(ReactJS)

I have written a code on my server(NodeJS) that will send a .csv file to the frontend with express res.download(path). I would like to know how I can handle the response with fetch API that will allow the frontend to download the file(.csv) sent.

I am using reactJs on my frontend.

7 months ago · Juan Pablo Isaza
1 answers
Answer question

0

I was able to solve this by using the downloadJs on my frontend

import download from 'downloadjs'
...
//get request
fetch(url).then(res => res.blob())
.then(blob => download(blob, 'name of file', 'data type')) // this line automatically starts a download operation
.catch(err => console.log(err));

I hope this helps you

7 months ago · Juan Pablo Isaza Report
Answer question
Find remote jobs