Note: This feature is available in Web Workers.
The bytes() method of the Request interface reads the request body and returns it as a promise that resolves with a Uint8Array.
bytes()None.
A promise that resolves with a Uint8Array.
TypeErrorThrown for one of the following reasons:
Content-Encoding header is incorrect).RangeErrorThrown if there is a problem creating the associated ArrayBuffer (for example, if the data size is too large).
const myArray = new Uint8Array(10);
const request = new Request("/myEndpoint", {
method: "POST",
body: myArray,
});
request.bytes().then((buffer) => {
// do something with the buffer sent in the request
});