当前位置:网站首页>Blob object introduction
Blob object introduction
2022-07-07 08:06:00 【DIU DIU's great God】
Blob Object represents an immutable 、 Class file object of original data . Its data can be read in text or binary format , It can also be converted into ReadableStream For data manipulation .
Look at the code below , You can use text construction Blob object
var debug = {
hello: "world"};
var blob = new Blob([JSON.stringify(debug, null, 2)], {
type : 'application/json'});
Example : Use Blob Create a pointer to a typed array URL
var typedArray = GetTheTypedArraySomehow();
var blob = new Blob([typedArray.buffer], {
type: 'application/octet-stream'}); // Pass in a suitable MIME type
var url = URL.createObjectURL(blob);
// It's going to produce something like blob:d3958f5c-0777-0845-9dcf-2cb28783acaf In this way URL character string
// You can use it like an ordinary URL Use it like that , For example, in img.src On .
Another read Blob The way of content in is to use Response object .
var text = await (new Response(blob)).text();
Sometimes the background download file is returned to the front end and converted to Blob object , During normal download , Return the correct file stream , When abnormal , The background returns a segment containing error information json , At this time, you need to prompt the user that the download failed , Look at the code below
/** * format blob Return value * @param {*} res */
const formatBlobResponse = async (res) => {
const text = await new Response(res).text();
let textObj = {
};
try {
textObj = JSON.parse(text);
} catch (e) {
}
if (text === '' || (textObj.code && Number(textObj.code) !== 200)) {
return {
success: false,
msg: textObj.msg || ' Download file failed , Please contact the Administrator ',
};
} else {
return {
success: true,
data: res,
};
}
};
边栏推荐
- Shell 脚本的替换功能实现
- 海信电视开启开发者模式
- Myabtis_Plus
- 让Livelink初始Pose与动捕演员一致
- QT learning 28 toolbar in the main window
- Bugku CTF daily one question chessboard with only black chess
- Visualization Document Feb 12 16:42
- Ansible
- Codeforce c.strange test and acwing
- [quick start of Digital IC Verification] 17. Basic grammar of SystemVerilog learning 4 (randomization)
猜你喜欢
Force buckle 144 Preorder traversal of binary tree
Notes on PHP penetration test topics
Qt学习26 布局管理综合实例
Detailed explanation of Kalman filter for motion state estimation
2022 welder (elementary) judgment questions and online simulation examination
Leetcode 90: subset II
These five fishing artifacts are too hot! Programmer: I know, delete it quickly!
[matlab] when matrix multiplication in Simulink user-defined function does not work properly, matrix multiplication module in module library can be used instead
【数字IC验证快速入门】10、Verilog RTL设计必会的FIFO
Real time monitoring of dog walking and rope pulling AI recognition helps smart city
随机推荐
Introduction to basic components of wechat applet
[advanced digital IC Verification] command query method and common command interpretation of VCs tool
Network learning (III) -- highly concurrent socket programming (epoll)
Thinkcmf6.0安装教程
buureservewp(2)
Recursive construction of maximum binary tree
It took "7" years to build the robot framework into a micro service
LeetCode简单题之判断一个数的数字计数是否等于数位的值
Chip design data download
C语言队列
Linux server development, MySQL index principle and optimization
青龙面板-今日头条
王爽 《汇编语言》之寄存器
UnityHub破解&Unity破解
2022 welder (elementary) judgment questions and online simulation examination
复杂网络建模(三)
追风赶月莫停留,平芜尽处是春山
Search for an element in a binary search tree (BST)
Paddlepaddle 29 dynamically modify the network structure without model definition code (relu changes to prelu, conv2d changes to conv3d, 2D semantic segmentation model changes to 3D semantic segmentat
Dedecms collects content without writing rules