当前位置:网站首页>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);
});边栏推荐
- Overview of database recovery
- Leetcode simple question check whether all characters appear the same number of times
- Shelved in TortoiseSVN- Shelve in TortoiseSVN?
- [Chongqing Guangdong education] National Open University autumn 2018 0088-21t Insurance Introduction reference questions
- Form artifact
- Database tuning solution
- 航海日答题小程序之航海知识竞赛初赛
- Leetcode simple question: find the nearest point with the same X or Y coordinate
- 实战:fabric 用户证书吊销操作流程
- Metaverse Ape猿界应邀出席2022·粤港澳大湾区元宇宙和web3.0主题峰会,分享猿界在Web3时代从技术到应用的文明进化历程
猜你喜欢

2022-07-05:给定一个数组,想随时查询任何范围上的最大值。 如果只是根据初始数组建立、并且以后没有修改, 那么RMQ方法比线段树方法好实现,时间复杂度O(N*logN),额外空间复杂度O(N*

Leetcode simple question ring and rod

Qtquick3d real time reflection

Learning of mall permission module

Leetcode simple question: the minimum cost of buying candy at a discount

boundary IoU 的计算方式

700. Search in a Binary Search Tree. Sol

A trip to Suzhou during the Dragon Boat Festival holiday

从 1.5 开始搭建一个微服务框架——日志追踪 traceId

The difference between MVVM and MVC
随机推荐
Livelocks and deadlocks of concurrency control
Postman核心功能解析-参数化和测试报告
Unique occurrence times of leetcode simple questions
请求二进制数据和base64格式数据的预览显示
Interview questions for famous enterprises: Coins represent a given value
Shelved in TortoiseSVN- Shelve in TortoiseSVN?
BFC block level formatting context
Practice: fabric user certificate revocation operation process
Serializability of concurrent scheduling
What about data leakage? " Watson k'7 moves to eliminate security threats
Leetcode simple question: the minimum cost of buying candy at a discount
[groovy] groovy dynamic language features (automatic type inference of function arguments in groovy | precautions for function dynamic parameters)
Nacos 的安装与服务的注册
Business learning of mall commodity module
Web3为互联网带来了哪些改变?
What if the files on the USB flash disk cannot be deleted? Win11 unable to delete U disk file solution tutorial
Oracle advanced query
元宇宙中的三大“派系”
Oracle is sorted by creation time. If the creation time is empty, the record is placed last
CA certificate trampled pit