当前位置:网站首页>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,
};
}
};
边栏推荐
- LeetCode简单题之字符串中最大的 3 位相同数字
- C language communication travel card background system
- Qt学习26 布局管理综合实例
- You Li takes you to talk about C language 6 (common keywords)
- 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
- C language flight booking system
- 2022 simulated examination question bank and online simulated examination of tea master (primary) examination questions
- Linux Installation MySQL 8.0 configuration
- Blob 对象介绍
- Record a stroke skin bone error of the skirt
猜你喜欢
Leetcode 40: combined sum II
json 数据展平pd.json_normalize
青龙面板-今日头条
Open source ecosystem | create a vibrant open source community and jointly build a new open source ecosystem!
Ansible
Real time monitoring of dog walking and rope pulling AI recognition helps smart city
【数字IC验证快速入门】11、Verilog TestBench(VTB)入门
Leetcode 90: subset II
These five fishing artifacts are too hot! Programmer: I know, delete it quickly!
Network learning (III) -- highly concurrent socket programming (epoll)
随机推荐
LeetCode简单题之判断一个数的数字计数是否等于数位的值
芯片资料 网站 易特创芯
DNS server configuration
Leetcode 40: combined sum II
芯片 设计资料下载
Thinkcmf6.0 installation tutorial
Recursive method constructs binary tree from middle order and post order traversal sequence
贝叶斯定律
JSON data flattening pd json_ normalize
Yugu p1020 missile interception (binary search)
2022 recurrent training question bank and answers of refrigeration and air conditioning equipment operation
2022制冷与空调设备运行操作复训题库及答案
青龙面板--花花阅读
Qt学习28 主窗口中的工具栏
Linux server development, MySQL index principle and optimization
Quickly use Jacobo code coverage statistics
青龙面板--整理能用脚本
Zsh shell adds automatic completion and syntax highlighting
Recursive method to construct binary tree from preorder and inorder traversal sequence
Chip information website Yite Chuangxin