方法
HTTP响应头属性
1、Content-Type
2、Content-Disposition (提供下载的实现)
3、Content-Length
例子
图片下载
视频下载
返回文件体下载文件
const res = await downloadApi({});
const blob = new Blob([res.data], {
type: 'image/jpeg'
})
const objectUrl = URL.createObjectURL(blob)
const link = document.createElement('a');
link.href = objectUrl;
link.setAttribute('download', 'name');
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
参考文章
- base64 , blob,url图片的处理方式 https://juejin.im/post/5c7546a6e51d45619d253bb3