当前位置:网站首页>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,
};
}
};
边栏推荐
- Implementation of replacement function of shell script
- [advanced digital IC Verification] command query method and common command interpretation of VCs tool
- QT learning 26 integrated example of layout management
- Rust versus go (which is my preferred language?)
- Lattice coloring - matrix fast power optimized shape pressure DP
- Linux Installation MySQL 8.0 configuration
- Who has docker to install MySQL locally?
- Linux server development, redis protocol and asynchronous mode
- 数据库实时同步利器——CDC(变化数据捕获技术)
- Relevant data of current limiting
猜你喜欢

快速使用 Jacoco 代码覆盖率统计

JS cross browser parsing XML application

Force buckle 145 Binary Tree Postorder Traversal

MySQL multi column index (composite index) features and usage scenarios

2022 tea master (intermediate) examination questions and mock examination

These five fishing artifacts are too hot! Programmer: I know, delete it quickly!

Record a stroke skin bone error of the skirt

Yugu p1020 missile interception (binary search)

王爽 《汇编语言》之寄存器

Linux server development, MySQL transaction principle analysis
随机推荐
B. Value sequence thinking
Recursive construction of maximum binary tree
调用 pytorch API完成线性回归
Search for an element in a binary search tree (BST)
基于Pytorch 框架手动完成线性回归
jeeSite 表单页面的Excel 导入功能
青龙面板--整理能用脚本
ROS Bridge 笔记(05)— carla_ackermann_control 功能包(将Ackermann messages 转化为 CarlaEgoVehicleControl 消息)
buureservewp(2)
Leetcode 90: subset II
【数字IC验证快速入门】12、SystemVerilog TestBench(SVTB)入门
These five fishing artifacts are too hot! Programmer: I know, delete it quickly!
Qt学习28 主窗口中的工具栏
Cnopendata American Golden Globe Award winning data
Téléchargement des données de conception des puces
The element with setfieldsvalue set is obtained as undefined with GetFieldValue
Recursive method constructs binary tree from middle order and post order traversal sequence
【踩坑系列】uniapp之h5 跨域的问题
2022制冷与空调设备运行操作复训题库及答案
青龙面板-今日头条