Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Response.blob(): read a response body as a Blob

The response.blob() method reads the entire response body and returns a Promise<Blob> containing its bytes.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

response.blob() // Promise<Blob>

Response.blob here means the instance method response.blob(), not a static method. It takes no arguments. It reads the entire body into a Blob; its MIME type comes from Content-Type, or is "" when none is recognized.

If response.body is null, repeated calls to response.blob() can each resolve to an empty Blob. If the response has a body stream, the promise rejects with TypeError when the stream is locked or disturbed (for example, because reading has already started or the stream was canceled). To read a streamed body twice, call response.clone() before reading. Stream errors also reject the promise.

The method does not check response.ok. This is a Fetch Standard Web API, not an ECMAScript-edition feature; check availability in your target environment.

Examples

async function main() {
  const response = new Response("Hello", {
    headers: { "Content-Type": "text/plain" }
  });
  const blob = await response.blob();

  console.log(blob.size);
  console.log(blob.type);
  console.log(response.bodyUsed);
}

main().catch(console.error);

Result

5
text/plain
true

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources