A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/zh-CN/docs/Web/API/Response/blob below:

Response.blob() - Web API | MDN

Response.blob()

Baseline Widely available

Response 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;
  });
规范 浏览器兼容性 参见

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4