当前位置:网站首页>Download the OSS file and modify the file name
Download the OSS file and modify the file name
2022-06-23 07:28:00 【But I love you】
oss The files on the can be created dynamically directly a Tag to download , But the downloaded file name is oss Given , Not converted to blob Type a.download It's invalid
First convert the file into a file stream , Then dynamically create a label , change a.download Property to change the file name
1. Download the file as a stream file
function getBlob(url) {
// url: It's the file in oss Address on
return new Promise(resolve => {
const xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.responseType = "blob";// The request type is blob type
xhr.crossOrigin = "*"; // Solving cross domain problems
xhr.onload = () => {
if (xhr.status === 200) {
resolve(xhr.response);
}
};
xhr.send();
});
}
2. Download the file and rename it
function saveAs(blob, filename) {
if (window.navigator.msSaveOrOpenBlob) {
navigator.msSaveBlob(blob, filename);
} else {
const link = document.createElement("a");
const body = document.querySelector("body");
link.href = window.URL.createObjectURL(blob);
link.download = filename; // Change file name
link.style.display = "none";
body.appendChild(link);
link.click();
body.removeChild(link);
window.URL.revokeObjectURL(link.href);
}
}
3. Use
getBlob(url).then(res =>{
//url: The file in oss Address on
saveAs(res,filename) // filename: file name , Customizable
})
边栏推荐
- U-Net: Convolutional Networks for Biomedical Image Segmentation
- [AI practice] xgb Xgbregression multioutputregressor parameter 1
- The original cloud landed in deep water, and the cloud product family of Boyun container released four values
- Product axure9 (English version), prototype design and production pull-down secondary menu
- ldconfig 命令
- leetcode210. Schedule II 207 Curriculum topology sorting DFS BFS
- MySQL (IV) - MySQL storage engine
- junit单元测试报错org.junit.runners.model.InvalidTestClassError: Invalid test class ‘xxx‘ .No runnable meth
- MySQL (VIII) - explain
- Pagoda forgot password
猜你喜欢

JS to determine the added and decreased elements of two arrays

Simpledateformat thread safety issues

传智教育 | 多人协作开发出现代码冲突,如何合并代码?

传智教育 | 项目发布前如何打tag标签及标签命名规范
![[game theory] basic knowledge](/img/eb/08b1ce5106e574dc42be58f72fbab9.jpg)
[game theory] basic knowledge

Product axure9 (English version), prototype design and production pull-down secondary menu

MYSQL牛客刷题

Regular expression graph and text ultra detailed summary without rote memorization (Part 1)

【PyQt5系列】修改计数器实现控制

deeplab v3 代码结构图
随机推荐
315. calculate the number of elements on the right that are smaller than the current element
Principle of skip table
Deep learning series 47: Super sub model real esrgan
leetcode210. Schedule II 207 Curriculum topology sorting DFS BFS
作为思摩尔应对气候变化紧急事件的一项举措,FEELM加入碳披露项目
How to verify date format in PHP (regular)
Spock约束-调用频率/目标/方法参数
Product axure9 (English version), prototype design background dynamic secondary menu display content
Flannel 工作原理
312. poke the balloon
. H5 file forgets the database name and uses h5py to print
Specific help of OSI layered model to work
CIRIUM(睿思誉)逐渐成为航空公司二氧化碳排放报告的标准
【AI实战】xgb.XGBRegressor之多回归MultiOutputRegressor调参1
Ldconfig command
Operation on a bit of binary
Spock-sub打桩
[game theory] basic knowledge
数据库原理实验测试题,关于图书分类表
Nacos adapts Oracle11g create table DDL statement