当前位置:网站首页>Download File blob transcoding
Download File blob transcoding
2022-06-25 13:17:00 【liminla!】
// Download the file ( Method 1)
export function download(data, name) {
if (!data) {
return
}
const getDate = new Date().getFullYear() + String((new Date().getMonth() + 1) < 10 ? `0${
String(new Date().getMonth() + 1)}` : (new Date().getMonth() + 1)) + new Date().getDate()
const blob = new Blob([data])
const fileName = `${
name}-${
getDate}.xls`;
if ('download' in document.createElement('a')) {
// No IE browser
const url = window.URL.createObjectURL(blob)
const link = document.createElement('a')
link.style.display = 'none'
link.href = url
link.setAttribute('download', fileName)
document.body.appendChild(link)
link.click()
document.body.removeChild(link) // Download complete remove element
window.URL.revokeObjectURL(url) // release blob object
} else {
// IE 10+
window.navigator.msSaveBlob(blob, fileName)
}
}
// Download the file ( Method 2)
export function download(res, name) {
const newBlob = new Blob([res]);
const anchor = document.createElement("a");
anchor.download = `${
name}.xlsx`;
anchor.href = window.URL.createObjectURL(newBlob);
anchor.click();
}
export function exportData(params) {
const formData = new FormData();
formData.append('jsonParam', params.jsonParam)
return axios({
method: 'get',
url: `${
process.env.VUE_APP_API_URL}/?jsonParam=${
encodeURI(params.jsonParam)}`,
data: formData,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'X-Access-Token': window.localStorage.getItem("token"),
'work-space-id': JSON.parse(window.sessionStorage.getItem("workSpace"))?.id,
responseType: 'blob'
}
})
.then(res => {
download(res.data, ` Query data ${
params.name}`)
return res.data
})
.catch(err => console.log(err));
}
边栏推荐
- [flask tutorial] flask development foundation and introduction
- 中国虚拟人哪家强?沙利文、IDC:小冰百度商汤位列第一梯队
- 一篇文章讲清楚MySQL的聚簇/联合/覆盖索引、回表、索引下推
- Summary of leetcode linked list problem solving skills
- 用include what you use拯救混乱的头文件
- 剑指 Offer II 029. 排序的循环链表
- Sword finger offer day 3 string (simple)
- [turn] starting from the end, analyze in detail how to fill in the college entrance examination volunteer
- Stockage des données en mémoire
- Summer Ending
猜你喜欢

Serevlt初识

Update PIP & Download jupyter Lab

Optimization of lazyagg query rewriting in parsing data warehouse
![[AI helps scientific research] fool drawing of loss curve](/img/38/5cb2a3d33a609dab3874215d5f7b5b.png)
[AI helps scientific research] fool drawing of loss curve

KDD 2022 | GraphMAE:自监督掩码图自编码器

Serenvlt first met

Capabilities required by architects

The editor is used every day. What is the working principle of language service protocol?

深圳民太安智能二面_秋招第一份offer

It's an artifact to launch a website in a few minutes
随机推荐
Three lines of code to simply modify the project code of the jar package
Drawing cubes with Visio
AGCO AI frontier promotion (6.25)
Using swiper to realize seamless rotation of multiple slides
Jenkins pipeline uses
And console Log say goodbye
Used in time filter (EL table)
剑指 Offer 第 1 天栈与队列(简单)
Always maintain epidemic prevention and control and create a safe and stable social environment
J2EE从入门到入土01.MySQL安装
关于数据在内存中存储的相关例题
《MongoDB入门教程》第01篇 MongoDB简介
Summer Ending
[pit avoidance refers to "difficult"] antd cascader implements new customized functions
[pit avoidance means "difficult"] antd select fuzzy search
[pit avoidance refers to "difficult"] halfcheckedkeys rendering problem in semi selected status of antd tree
20220620 interview reply
Native JS --- infinite scrolling
Sword finger offer 04 Find in 2D array
[pit avoidance means "difficult"] the antd form dynamic form is deleted, and the first line is displayed by default