当前位置:网站首页>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
})
边栏推荐
- 细说Idea那些骚操作
- 316. remove duplicate letters
- Initialization layer implementation
- In depth learning series 46: face image super score gfp-gan
- npm下载报错npm ERR code ERESOLVE
- MySQL (VIII) - explain
- ldconfig 命令
- [AI practice] xgbgressor model accelerates training and uses GPU to train xgbgressor in seconds
- Cirium has gradually become the standard for airlines' carbon dioxide emission reporting
- Heterogeneous transaction scenario interaction process and consistency assurance
猜你喜欢

MySQL (11) - sorting out MySQL interview questions

Live broadcast review | how can the container transformation of traditional applications be fast and stable?

初始化层实现

Yolov5 detecting small targets (with source code)

MySQL(八) — 执行计划(Explain)详解

PSP code implementation

闫氏DP分析法

对二进制的某一位操作

Sstable details

Product axure9 (English version), prototype design background dynamic secondary menu display content
随机推荐
GloRe
How flannel works
MySQL (IV) - MySQL storage engine
306. Addenda
char和varchar区别
MYSQL牛客刷题
. H5 file forgets the database name and uses h5py to print
Solutions to abnormal network connection of Xiaoai speakers
Here comes the dry goods | PAAS collection to see first ~
deeplab v3 代码结构图
Redis设置密码
跳跃表原理
Simpledateformat thread safety issues
【AI实战】XGBRegressor模型加速训练,使用GPU秒级训练XGBRegressor
Database principle experiment test questions, about book classification table
Both are hard disk partitions. What is the difference between C disk and D disk?
Difference between char and varchar
g++编译命令使用
Unet代码实现
PSP代码实现