2 回答

TA貢獻1848條經(jīng)驗 獲得超2個贊
我發(fā)現(xiàn)解決這個問題的唯一方法是:在響應(yīng)頭中發(fā)送文件名和擴展名,然后手動解析它們。像:在春天:
myControllerMethod( HttpServletResponse response){
...
response.setContentType(att.getType());
response.setHeader("Content-Disposition", "attachment; filename=\"" + myFileName + "\"");
}
在反應(yīng):
const headers = response.headers;
const file = headers.get("Content-Disposition");
然后手動解析這個“文件”以獲取文件名;

TA貢獻1799條經(jīng)驗 獲得超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();
});
添加回答
舉報