Object size (content length)?

Any idea why I can’t always obtain the object size? I can use resp.headers.get('content-length') || '0' to find the size when the content-length header exists, but if it doesn’t exist then I’m out of luck. I know the file exists in cache, why can’t I obtain the file size?

Is your question how to get the size of the response body?

iirc content-length is usually response body + response headers combined so yes.

If present, the content length only refers to the body, never the header.

But are you basically after the size of the body?


There might be a better approach, but the following might just do the trick

const buf = await response.clone().arrayBuffer();

ehhh that’s kind of a hack, makes sense though. it needs to be in an async function i think.

It is, but it does not seem as if there was a straightforward way otherwise.

As for “async”, you can also simply play with the Promise arrayBuffer() returns, however you wont be able to do it in a synchronous fashion in any case - welcome to JavaScript’s callback heII :smile:

yeah needs to be async. appreciate the help!