当前位置:网站首页>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,
};
}
};
边栏推荐
- Real time monitoring of dog walking and rope pulling AI recognition helps smart city
- Yugu p1020 missile interception (binary search)
- Leetcode 40: combined sum II
- 2022焊工(初级)判断题及在线模拟考试
- MySQL multi column index (composite index) features and usage scenarios
- Minimum absolute difference of binary search tree (use medium order traversal as an ordered array)
- OpenJudge NOI 2.1 1752:鸡兔同笼
- C language communication travel card background system
- Shell 脚本的替换功能实现
- C language flight booking system
猜你喜欢

Empire CMS collection Empire template program general

QT learning 28 toolbar in the main window

【数字IC验证快速入门】10、Verilog RTL设计必会的FIFO

Niu Mei's mathematical problem --- combinatorial number

【数字IC验证快速入门】15、SystemVerilog学习之基本语法2(操作符、类型转换、循环、Task/Function...内含实践练习)

LeetCode简单题之字符串中最大的 3 位相同数字

探索干货篇!Apifox 建设思路

Linux server development, redis protocol and asynchronous mode

Quickly use Jacobo code coverage statistics

LeetCode中等题之我的日程安排表 I
随机推荐
2022年茶艺师(中级)考试试题及模拟考试
Yugu p1020 missile interception (binary search)
复杂网络建模(一)
【数字IC验证快速入门】17、SystemVerilog学习之基本语法4(随机化Randomization)
Implementation of replacement function of shell script
Most elements
QT learning 28 toolbar in the main window
Minimum absolute difference of binary search tree (use medium order traversal as an ordered array)
Recursive method to construct binary tree from preorder and inorder traversal sequence
Téléchargement des données de conception des puces
芯片 设计资料下载
json 数据展平pd.json_normalize
Search for an element in a binary search tree (BST)
Cnopendata American Golden Globe Award winning data
padavan手动安装php
2022 welder (elementary) judgment questions and online simulation examination
Open source ecosystem | create a vibrant open source community and jointly build a new open source ecosystem!
Example of file segmentation
调用 pytorch API完成线性回归
【数字IC验证快速入门】12、SystemVerilog TestBench(SVTB)入门