当前位置:网站首页>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
})
边栏推荐
猜你喜欢

Solutions to abnormal network connection of Xiaoai speakers

Pagoda forgot password

Deep learning series 47: Super sub model real esrgan

In depth learning series 46: face image super score gfp-gan

Sstable details

CIRIUM(睿思誉)逐渐成为航空公司二氧化碳排放报告的标准

NTU-RGBD数据集下载及数据格式解析

Product axure9 (English version), prototype design background dynamic secondary menu display content

【博弈论】基础知识

跳跃表原理
随机推荐
[AI practice] xgb Xgbregression multioutputregressor parameter 1
细说Idea那些骚操作
对二进制的某一位操作
如何达到高效的网络信息传播
异构交易场景交互流程及一致性保证
901. stock price span
U-Net: Convolutional Networks for Biomedical Image Segmentation
NPM download error NPM err code error
Pagoda forgot password
GloRe
paddle版本问题
NTU-RGBD数据集下载及数据格式解析
MySQL summary
Redis设置密码
TensorFlow中的数据类型
‘latin-1‘ codec can‘t encode characters in position 103-115: Body (‘一串中文‘) is not valid Latin-1
Product axure9 (English version), prototype design background dynamic secondary menu display content
g++编译命令使用
MySQL(二) — MySQL数据类型
20bn Jester complete dataset Download