当前位置:网站首页>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);
});
边栏推荐
- Why does the C# compiler allow an explicit cast between IEnumerable< T> and TAlmostAnything?
- Talking about MySQL index
- 2022-07-05: given an array, you want to query the maximum value in any range at any time. If it is only established according to the initial array and has not been modified in the future, the RMQ meth
- Pinctrl subsystem and GPIO subsystem
- Serializability of concurrent scheduling
- 70. Climbing Stairs. Sol
- Metaverse Ape猿界应邀出席2022·粤港澳大湾区元宇宙和web3.0主题峰会,分享猿界在Web3时代从技术到应用的文明进化历程
- Interview questions for famous enterprises: Coins represent a given value
- [groovy] groovy dynamic language features (automatic type inference of function arguments in groovy | precautions for function dynamic parameters)
- Concurrency control of performance tuning methodology
猜你喜欢
Nacos 的安装与服务的注册
Database recovery strategy
Official clarification statement of Jihu company
Matlab draws a cute fat doll
Metaverse Ape猿界应邀出席2022·粤港澳大湾区元宇宙和web3.0主题峰会,分享猿界在Web3时代从技术到应用的文明进化历程
Blocking of concurrency control
The difference between MVVM and MVC
What about data leakage? " Watson k'7 moves to eliminate security threats
A trip to Suzhou during the Dragon Boat Festival holiday
Pl/sql basic case
随机推荐
Pl/sql basic case
QT creator 7-cmake update
Cobaltstrike builds an intranet tunnel
50. Pow(x, n). O(logN) Sol
Type of fault
boundary IoU 的计算方式
Leetcode simple question check whether all characters appear the same number of times
南京:全面启用商品房买卖电子合同
Draw a red lantern with MATLAB
科技云报道:算力网络,还需跨越几道坎?
1.3 years of work experience, double non naked resignation agency face-to-face experience [already employed]
Interprocess communication in the "Chris Richardson microservice series" microservice architecture
Lightweight dynamic monitorable thread pool based on configuration center - dynamictp
Leetcode simple question: check whether each row and column contain all integers
Learning of mall permission module
Understand the basic concept of datastore in Android kotlin and why SharedPreferences should be stopped in Android
笔记本电脑蓝牙怎么用来连接耳机
How to reverse a string fromCharCode? - How to reverse String. fromCharCode?
Index optimization of performance tuning methodology
如何開發引入小程序插件