2017-09-26 62 views

回答

1

在客戶端可以使用:

$http({method: 'GET', url: '/someUrl'}). 
success(function(data, status, headers, config) { 
    let blob = new Blob([data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }); 
    const fileName = `file.xlsx`; 
    let file = new File([blob], fileName); 
    let fileUrl = URL.createObjectURL(file); 
}) 
.error(function(data, status, headers, config){ 
}); 

我使用的文件,因爲它允許你通過文件名。你可以跳過這部分並將Blob傳遞給URL.createObjectURL。它隨着下載打開窗口。假設你的服務器代碼是正確的。但是如果你在Chrome中看到緩衝區而不是它發送的東西。

對於服務器端我通常使用快遞res.sendFile。它需要你創建一個文件,以便你清理。

+0

如何從AngularJS客戶端下載的NodeJS XLSX的文件流?任何想法? –

+0

我用$ http調用了編輯答案。 – barnski