Blob: type property
The type property is the content type of the Blob, such as 'image/png'.
Value
A string.
- Read-only. Assigning to it throws
TypeError. - For a
Blobcreated withnew Blob(), it'soptions.type, defaulting to an empty string. - For a
Blobfromres.blob(), it's an empty string; theContent-Typeresponse header isn't used. - When a
Blobis used as the request body offetch(), iftypeisn't empty and noContent-Typeis written, it becomes the request'sContent-Type.
Examples
js
async function main() {
const bytes = new Uint8Array([0, 255, 16, 128]);
const blob = new Blob([bytes], { type: 'application/octet-stream' });
const res = await fetch('https://httpbin.org/post', { method: 'POST', body: blob });
const echo = await res.json();
console.log(echo.headers['Content-Type']);
}
main();Result: prints application/octet-stream.
Differences from the web
For a Blob from res.blob() it's an empty string. On the web it comes from Content-Type.