2 回答
TA贡献1848条经验 获得超2个赞
我发现解决这个问题的唯一方法是:在响应头中发送文件名和扩展名,然后手动解析它们。像:在春天:
myControllerMethod( HttpServletResponse response){
...
response.setContentType(att.getType());
response.setHeader("Content-Disposition", "attachment; filename=\"" + myFileName + "\"");
}
在反应:
const headers = response.headers;
const file = headers.get("Content-Disposition");
然后手动解析这个“文件”以获取文件名;
TA贡献1799条经验 获得超6个赞
以这种方式尝试,它可能会帮助您:
fetch('http://localhost:8080/employees/download')
.then(response => {
response.blob().then(blob => {
let url = window.URL.createObjectURL(blob);
let a = document.createElement('a');
a.href = url;
a.download = 'employees.json';
a.click();
});
添加回答
举报
