当前位置:网站首页>Request preview display of binary data and Base64 format data
Request preview display of binary data and Base64 format data
2022-07-05 22:26:00 【ws_ code_ csdn】
1、 Request binary data , Preview display of data in various formats .
axios({
method: 'get',
url: `getFile/${type}`,
headers: {
Authorization: userStore.token,
},
// It's necessary here 'blob'
responseType: 'blob',
}).then((res: any) => {
// pdf Format
if (type == 1) {
let blob = new Blob([res.data], { type: 'application/pdf' });
pdfSrc.value = URL.createObjectURL(blob);
window.open(pdfSrc.value);
} else if (type == 2) {
// picture jpeg Format
let blob = new Blob([res.data], { type: 'image/jpeg' });
imgSrc.value = window.URL.createObjectURL(blob);
} else if (type == 3) {
// Audio
let blob = new Blob([res.data], { type: 'wav/audio' });
if (audio.value) {
audio.value.src = window.URL.createObjectURL(blob);
audio.value.play();
}
} else if (type == 4) {
// picture excel Format
const link = document.createElement('a');
let blob = new Blob([res.data], { type: 'application/vnd.ms-excel' });
link.style.display = 'none';
link.href = URL.createObjectURL(blob); // Create a URL
link.setAttribute('download', ` Table resources ${new Date().getTime()}.xls`);
document.body.appendChild(link);
link.click(); // Trigger download
document.body.removeChild(link);
}
});
Be careful :
A、 To put responseType Set to ‘blob’;
B、 The corresponding type Set it up , Such as the picture new Blob([res.data], { type: 'image/jpeg' }).
2、base64 Format data picture preview display
getOperImg()
.then((res) => {
if (res) {
const { code, data } = res;
if (code == 200) {
if (Array.isArray(data) && data.length != 0) {
const { operPic } = data[0];
// operPic It's a request base64 Picture data
// The final picture address Requires front stitching data:image/jpg;base64,
imgSrc.value = `data:image/jpg;base64,${operPic}`;
}
}
}
})
.catch((err) => {
console.log(' Get photo ', err);
});
边栏推荐
- 點到直線的距離直線的交點及夾角
- Assign the output of a command to a variable [repeat] - assigning the output of a command to a variable [duplicate]
- Common interview questions of JVM manufacturers
- Solutions for unexplained downtime of MySQL services
- 二叉树(三)——堆排序优化、TOP K问题
- How to develop and introduce applet plug-ins
- FBO and RBO disappeared in webgpu
- Livelocks and deadlocks of concurrency control
- thinkphp5.1跨域问题解决
- Platformio create libopencm3 + FreeRTOS project
猜你喜欢
Metaverse ape ape community was invited to attend the 2022 Guangdong Hong Kong Macao Great Bay metauniverse and Web3.0 theme summit to share the evolution of ape community civilization from technology
Kubernetes Administrator certification (CKA) exam notes (IV)
2022软件测试工程师涨薪攻略,3年如何达到30K
EasyCVR集群部署如何解决项目中的海量视频接入与大并发需求?
Sentinel production environment practice (I)
Overview of database recovery
How to quickly experience oneos
Win11缺少dll文件怎么办?Win11系统找不到dll文件修复方法
Recovery technology with checkpoints
Postman核心功能解析-参数化和测试报告
随机推荐
Metaverse Ape获Negentropy Capital种子轮融资350万美元
Wonderful review of the digital Expo | highlight scientific research strength, and Zhongchuang computing power won the digital influence enterprise award
FBO and RBO disappeared in webgpu
How to reverse a string fromCharCode? - How to reverse String. fromCharCode?
boundary IoU 的计算方式
Postman core function analysis - parameterization and test report
Implementation technology of recovery
Pl/sql basic case
Technology cloud report: how many hurdles does the computing power network need to cross?
[agc009e] eternal average - conclusion, DP
如何開發引入小程序插件
Metaverse ape received $3.5 million in seed round financing from negentropy capital
点到直线的距离直线的交点及夹角
Nacos 的安装与服务的注册
70. Climbing Stairs. Sol
Blocking protocol for concurrency control
如何创建线程
Alternating merging strings of leetcode simple questions
Unique occurrence times of leetcode simple questions
EasyCVR集群部署如何解决项目中的海量视频接入与大并发需求?