Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. Response
  4. blob()

Response: blob() method

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2017.

Note: This feature is available inWeb Workers.

Theblob() method of theResponse interface takesaResponse stream and reads it to completion. It returns a promise thatresolves with aBlob.

Syntax

js
blob()

Parameters

None.

Note:If theResponse has aResponse.type of"opaque", the resultingBlobwill have aBlob.size of0 and aBlob.type ofempty string"", which renders ituseless for methods likeURL.createObjectURL().

Return value

A promise that resolves with aBlob whose data is the body's bytes and the media type is the response'sContent-Type header's value.

Exceptions

AbortErrorDOMException

The request wasaborted.

TypeError

Thrown for one of the following reasons:

Examples

In ourfetch request example (runfetch request live), wecreate a new request using theRequest() constructor,then use it to fetch a JPG. When the fetch is successful, we read aBlobout of the response usingblob(), put it into an object URL usingURL.createObjectURL(), and then set that URL as the source of an<img> element to display the image.

js
const myImage = document.querySelector("img");const myRequest = new Request("flowers.jpg");fetch(myRequest)  .then((response) => response.blob())  .then((myBlob) => {    const objectURL = URL.createObjectURL(myBlob);    myImage.src = objectURL;  });

Specifications

Specification
Fetch
# ref-for-dom-body-blob①

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2026 Movatter.jp