SpringBoot
private static void setResponseHeader(HttpServletResponse response, String fileName) {
try {
response.setContentType("application/octet-stream;charset=UTF-8");
response.setHeader("Content-Disposition", "attachment;filename="+ URLEncoder.encode(fileName, "UTF-8"));
response.addHeader("Pargam", "no-cache");
response.addHeader("Cache-Control", "no-cache");
} catch (Exception ex) {
ex.printStackTrace();
}
}
Axios
this.axios.get("/api/sc/download/1", {responseType: 'blob'}).then(res=>{
let fileName = decodeURI(res.headers['content-disposition'].substring(20))
let url = window.URL.createObjectURL(new Blob([res.data]))
let link= document.createElement('a')
link.style.display='none'
link.href=url
link.setAttribute('download', fileName)
document.body.appendChild(link)
link.click()
})