Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

react download file from express res.download

let downloadHandler = (e) =>{
      const fileName = e.target.parentElement.id;
    axios({
        method: 'get',
        url: 'http://localhost:3001/download/'+fileName,
        responseType: 'blob',
        headers: {},
        })
        .then((res) => {
            const url = window.URL.createObjectURL(new Blob([res.data]));
            const link = document.createElement('a');
            link.href = url;
            link.setAttribute('download', fileName);
            document.body.appendChild(link);
            link.click();
        })
        .catch((error) => {
            alert(error);
        })
  }
Comment

PREVIOUS NEXT
Code Example
Javascript :: check if object has method javascript 
Javascript :: jquery nice select 
Javascript :: find highest value in array javascript 
Javascript :: render markdown in nextjs 
Javascript :: vue js computed 
Javascript :: delete a node in dom javascript 
Javascript :: mongoose update and return new 
Javascript :: mongoose virtual 
Javascript :: dayjs now 
Javascript :: add tailwind to vue 
Javascript :: how to load existing json data in nuxt 
Javascript :: file extension name in js 
Javascript :: javascript tofixed is not a function 
Javascript :: nodejs bodyparser form data 
Javascript :: conditional style prop react 
Javascript :: upload preview image js 
Javascript :: Easy REACT download image 
Javascript :: add array to array javascript 
Javascript :: js execute string 
Javascript :: stop a site from reloading javascript 
Javascript :: js filter out doubles 
Javascript :: string indexing in js 
Javascript :: js key value array 
Javascript :: copy text to clipboard reactjs 
Javascript :: mongodb sort 
Javascript :: sort array object 
Javascript :: use of .json() in javascript 
Javascript :: javascript remove query string from url 
Javascript :: js copy array into another 
Javascript :: sfc in react 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =