当前位置:网站首页>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,
};
}
};
边栏推荐
- Binary tree and heap building in C language
- game攻防世界逆向
- 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
- LeetCode简单题之判断一个数的数字计数是否等于数位的值
- 快解析内网穿透助力外贸管理行业应对多种挑战
- Implementation of replacement function of shell script
- [Matlab] Simulink 自定义函数中的矩阵乘法工作不正常时可以使用模块库中的矩阵乘法模块代替
- Empire CMS collection Empire template program general
- [UVM practice] Chapter 2: a simple UVM verification platform (2) only driver verification platform
- DNS server configuration
猜你喜欢
2022焊工(初级)判断题及在线模拟考试
Qt学习27 应用程序中的主窗口
2022 recurrent training question bank and answers of refrigeration and air conditioning equipment operation
快解析内网穿透助力外贸管理行业应对多种挑战
json 数据展平pd.json_normalize
Myabtis_Plus
有 Docker 谁还在自己本地安装 Mysql ?
2022 tea master (intermediate) examination questions and mock examination
Linux server development, MySQL transaction principle analysis
Explore dry goods! Apifox construction ideas
随机推荐
Quickly use Jacobo code coverage statistics
Linux server development, MySQL process control statement
芯片资料 网站 易特创芯
Implementation of replacement function of shell script
Avatary的LiveDriver试用体验
Linux Installation MySQL 8.0 configuration
Recursive construction of maximum binary tree
[VHDL parallel statement execution]
Blob 对象介绍
Network learning (III) -- highly concurrent socket programming (epoll)
Explore dry goods! Apifox construction ideas
青龙面板-今日头条
Find the mode in the binary search tree (use medium order traversal as an ordered array)
These five fishing artifacts are too hot! Programmer: I know, delete it quickly!
Cnopendata geographical distribution data of religious places in China
LeetCode简单题之字符串中最大的 3 位相同数字
Chip information website Yite Chuangxin
【数字IC验证快速入门】10、Verilog RTL设计必会的FIFO
追风赶月莫停留,平芜尽处是春山
快速使用 Jacoco 代码覆盖率统计