blob()
方法在
Body
mixin takes a
响应
stream and reads it to completion. It returns a promise that resolves with a
Blob
.
response.blob().then(function(myBlob) {
// do something with myBlob
});
None.
注意: 若
响应
拥有
Response.type
of
"opaque"
, the resulting
Blob
will have a
Blob.size
of
0
和
Blob.type
of empty string
""
, which renders it
useless
for methods like
URL.createObjectURL
.
A promise that resolves with a
Blob
.
In our
fetch request example
(run
fetch request live
), we create a new request using the
Request()
constructor, then use it to fetch a JPG. When the fetch is successful, we read a
Blob
out of the response using
blob()
, put it into an object URL using
URL.createObjectURL
, and then set that URL as the source of an
<img>
element to display the image.
var myImage = document.querySelector('img');
var myRequest = new Request('flowers.jpg');
fetch(myRequest)
.then(response => response.blob())
.then(function(myBlob) {
var objectURL = URL.createObjectURL(myBlob);
myImage.src = objectURL;
});
| 规范 | 状态 | 注释 |
|---|---|---|
|
Fetch
The definition of 'blob()' in that specification. |
实时标准 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
blob
|
Chrome
42
|
Edge ≤18 |
Firefox
39
|
IE No |
Opera
29
|
Safari 10 | WebView Android No | Chrome Android 42 | Firefox Android No |
Opera Android
29
|
Safari iOS 10 | Samsung Internet Android No |
完整支持
不支持
实验。期望将来行为有所改变。
用户必须明确启用此特征。
Body
arrayBuffer()
blob()
formData()
json()
text()