当前位置:网站首页>Introduction à l'objet blob
Introduction à l'objet blob
2022-07-07 08:06:00 【Dieu déchu】
Blob L'objet représente une variable、Objet de fichier de classe pour les données brutes.Ses données peuvent être lues en format texte ou binaire,Peut également être converti en ReadableStream Pour les opérations de données.
Regardez le code ci - dessous,Vous pouvez utiliser la construction de texte Blob Objet
var debug = {
hello: "world"};
var blob = new Blob([JSON.stringify(debug, null, 2)], {
type : 'application/json'});
Exemple:Utiliser Blob Créer un tableau dactylographié URL
var typedArray = GetTheTypedArraySomehow();
var blob = new Blob([typedArray.buffer], {
type: 'application/octet-stream'}); // Passer dans un MIME Type
var url = URL.createObjectURL(blob);
// Il en résultera un blob:d3958f5c-0777-0845-9dcf-2cb28783acaf Comme ça. URL String
// Vous pouvez utiliser comme d'habitude URL Utilise - le comme ça.,Comme dans img.src Allez..
Une autre lecture Blob La façon dont le contenu est utilisé est Response Objet.
var text = await (new Response(blob)).text();
À un moment donné, le fichier de téléchargement de fond retourné à l'avant est converti en Blob Objet, Téléchargement normal , Renvoie le bon flux de fichiers ,En cas d'anomalie, L'arrière - plan renvoie une section contenant un message d'erreur json , Vous devez demander à l'utilisateur que le téléchargement a échoué ,Regardez le code ci - dessous
/** * Formatage blob Valeur de retour * @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 || 'Impossible de télécharger le fichier,Veuillez contacter l'Administrateur',
};
} else {
return {
success: true,
data: res,
};
}
};
边栏推荐
- Linux server development, redis protocol and asynchronous mode
- Wechat applet data binding multiple data
- Linux server development, MySQL transaction principle analysis
- QT learning 26 integrated example of layout management
- 【VHDL 并行语句执行】
- Recursive method constructs binary tree from middle order and post order traversal sequence
- 2022 recurrent training question bank and answers of refrigeration and air conditioning equipment operation
- 【数字IC验证快速入门】12、SystemVerilog TestBench(SVTB)入门
- 这5个摸鱼神器太火了!程序员:知道了快删!
- 青龙面板--花花阅读
猜你喜欢

【数字IC验证快速入门】12、SystemVerilog TestBench(SVTB)入门

Yugu p1020 missile interception (binary search)

LeetCode 90:子集 II

Qt学习27 应用程序中的主窗口

Li Kou interview question 04.01 Path between nodes

Shell 脚本的替换功能实现

2022茶艺师(初级)考试题模拟考试题库及在线模拟考试

央视太暖心了,手把手教你写HR最喜欢的简历

追风赶月莫停留,平芜尽处是春山

Force buckle 144 Preorder traversal of binary tree
随机推荐
json 数据展平pd.json_normalize
Empire CMS collection Empire template program general
Leanote private cloud note building
Recursive construction of maximum binary tree
Qt学习27 应用程序中的主窗口
The charm of SQL optimization! From 30248s to 0.001s
互动送书-《Oracle DBA工作笔记》签名版
MySQL multi column index (composite index) features and usage scenarios
dash plotly
Jmeter 的使用
快速使用 Jacoco 代码覆盖率统计
Recursive method to verify whether a tree is a binary search tree (BST)
[CV] Wu Enda machine learning course notes | Chapter 8
Binary tree and heap building in C language
2022 welder (elementary) judgment questions and online simulation examination
【數字IC驗證快速入門】15、SystemVerilog學習之基本語法2(操作符、類型轉換、循環、Task/Function...內含實踐練習)
Most elements
Who has docker to install MySQL locally?
Linux Installation MySQL 8.0 configuration
Merging binary trees by recursion