当前位置:网站首页>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,
};
}
};
边栏推荐
- Network learning (III) -- highly concurrent socket programming (epoll)
- Chip information website Yite Chuangxin
- [CV] Wu Enda machine learning course notes | Chapter 8
- Zsh shell adds automatic completion and syntax highlighting
- The zblog plug-in supports the plug-in pushed by Baidu Sogou 360
- 【数字IC验证快速入门】15、SystemVerilog学习之基本语法2(操作符、类型转换、循环、Task/Function...内含实践练习)
- Binary tree and heap building in C language
- C language flight booking system
- [UVM foundation] what is transaction
- Thinkcmf6.0安装教程
猜你喜欢
2022 simulated examination question bank and online simulated examination of tea master (primary) examination questions
Leetcode 90: subset II
Ansible
快解析内网穿透为文档加密行业保驾护航
Network learning (III) -- highly concurrent socket programming (epoll)
Dedecms collects content without writing rules
Wechat applet data binding multiple data
Linux server development, redis protocol and asynchronous mode
Qt学习26 布局管理综合实例
jeeSite 表单页面的Excel 导入功能
随机推荐
Zsh shell adds automatic completion and syntax highlighting
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
Visualization Document Feb 12 16:42
Linux server development, redis protocol and asynchronous mode
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after conne
Figure out the working principle of gpt3
快解析内网穿透为文档加密行业保驾护航
大视频文件的缓冲播放原理以及实现
2022 Inner Mongolia latest advanced fire facility operator simulation examination question bank and answers
2022 National latest fire-fighting facility operator (primary fire-fighting facility operator) simulation questions and answers
QT learning 26 integrated example of layout management
Who has docker to install MySQL locally?
2022 recurrent training question bank and answers of refrigeration and air conditioning equipment operation
互动送书-《Oracle DBA工作笔记》签名版
探索干货篇!Apifox 建设思路
Most elements
【VHDL 并行语句执行】
Installing postgresql11 database under centos7
Qt学习28 主窗口中的工具栏
Lattice coloring - matrix fast power optimized shape pressure DP