文件下载
<h2>文件流形式下载文件</h2>
<pre><code class="language-javascript"> downFile (row) { //${API.attachment}/download
let url = null;
if (row.url.includes('group')) {
url = row.url;
} else {
url = decode(row.url);
}
AttachmentManageService.downFile(url).then(respones => {
console.log(respones)
var blob = new Blob([respones.data], { type: 'application/actet-stream;charset=utf-8' })
var downloadElement = document.createElement('a');
var href = window.URL.createObjectURL(blob); //创建下载的链接
downloadElement.href = href;
downloadElement.download = row.originalName; //下载后文件名
document.body.appendChild(downloadElement);
downloadElement.click(); //点击下载
document.body.removeChild(downloadElement); //下载完成移除元素
window.URL.revokeObjectURL(href); //释放掉blob对象
})
},</code></pre>
<pre><code class="language-javascript"> downFile(url) {
//window.open(`${API.attachment}/download?url=${data}`)
return request({
// headers:{responseType: 'arraybuffer'},
url: `${API.attachment}/download?file=${url}`,
method: 'post',
data: {},
responseType: 'arraybuffer'
})
}</code></pre>