We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS

这篇翻译不完整。请帮忙从英语翻译这篇文章

Body  mixin的 blob()方法使用一个 Response 流,并将其读取完成。它返回一个使用Blob解决的promise。

句法

response.blob().then(function(myBlob) {
  // do something with myBlob
});

参数

None.

返回值

A promise that resolves with a Blob.

例子

在我们 fetch request example (run fetch request live)中,我们使用Request.Request构造方法创建了一个新的request对象,然后使用它来获取一个JPG文件。当fetch成功的时候,我们使用blob()从response中读取一个Blob对象,并使用URL.createObjectURL 将它放入一个object URL ,然后把URL设置为img元素的src属性以显示这张图片。

 

var myImage = document.querySelector('img');

var myRequest = new Request('flowers.jpg');

fetch(myRequest)
.then(function(response) {
  return response.blob();
})
.then(function(myBlob) {
  var objectURL = URL.createObjectURL(myBlob);
  myImage.src = objectURL;
});

规范

规范 状态 说明
Fetch
blob()
Living Standard  

浏览器兼容性

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 42 [1]
 
(Yes) 39 (39) [2] 未实现

29 [3]

未实现
Feature Android Edge Firefox Mobile (Gecko) Firefox OS (Gecko) IE Phone Opera Mobile Safari Mobile Chrome for Android
Basic support 未实现 (Yes) 未实现 未实现 未实现 未实现 未实现 未实现

[1] Behind a preference in version 41.

[2] Behind a preference starting with version 34.

[3] Behind a preference in version 28.

另见

文档标签和贡献者

标签: 
此页面的贡献者: fyzhu, xiaoyixiang, xgqfrms-GitHub, thomastao0215
最后编辑者: fyzhu,