通过POST下载.xls文件

时间:2017-10-26 12:44:11

标签: angularjs http post download

我正在使用AngularJS并在POST请求下载文件.xls

this.$http.post('/api/rept/detc/xls', params).then((response) => {                  
    let blob = new Blob([response], { 
        type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" 
    }),
    objectUrl = URL.createObjectURL(blob);
    window.open(objectUrl);
})

然后下载没有名称格式的文件(格式为:c65c45f8-e6a3-458d-xxxx-43c5fcxxxxx)。 如何在没有FileSave包的情况下下载?

1 个答案:

答案 0 :(得分:1)

类似的方法对我有用:

this.$http.post('/api/rept/detc/xls', params).then((response) => {                  
    let blob = new Blob([response]);
    let url = window.URL.createObjectURL(blob);
    let a = document.createElement('a');
    a.href = url;
    a.download = 'filename_here';
    a.target = '_blank';
    a.click();
})
相关问题