当前位置:网站首页>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,
};
}
};
边栏推荐
猜你喜欢

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

Linux server development, MySQL transaction principle analysis
![[CV] Wu Enda machine learning course notes | Chapter 8](/img/c0/7a39355fb3a6cb506f0fbcf2a7aa24.jpg)
[CV] Wu Enda machine learning course notes | Chapter 8

2022焊工(初级)判断题及在线模拟考试

开源生态|打造活力开源社区,共建开源新生态!

Implementation of replacement function of shell script

Linux server development, redis source code storage principle and data model

Network learning (III) -- highly concurrent socket programming (epoll)

2022 National latest fire-fighting facility operator (primary fire-fighting facility operator) simulation questions and answers

Few shot Learning & meta learning: small sample learning principle and Siamese network structure (I)
随机推荐
3D reconstruction - stereo correction
Avatary的LiveDriver试用体验
Few shot Learning & meta learning: small sample learning principle and Siamese network structure (I)
Codeforce c.strange test and acwing
芯片资料 网站 易特创芯
2022茶艺师(初级)考试题模拟考试题库及在线模拟考试
Visualization Document Feb 12 16:42
uniapp 移动端强制更新功能
[UVM foundation] what is transaction
Recursive method constructs binary tree from middle order and post order traversal sequence
jeeSite 表单页面的Excel 导入功能
[UVM practice] Chapter 2: a simple UVM verification platform (2) only driver verification platform
LeetCode简单题之找到一个数字的 K 美丽值
LeetCode简单题之判断一个数的数字计数是否等于数位的值
Network learning (II) -- Introduction to socket
Implementation of replacement function of shell script
Relevant data of current limiting
Linux server development, MySQL transaction principle analysis
dash plotly
Dedecms collects content without writing rules