Change Content-Length for file downloads

Hello! I am trying to change the Content-Length header, as I will use Cloudflare Workers to download files from a R2 bucket. I tried by changing the header manually, but it doesnt make a change. Then I read that it was not possible to change that header, and that the only way to do so is by using Streams.

Now, my question is how should I do that? I tried to do it (see the code below), however it does not work. Any advice is very much appreciated!

firmwareBin = await env.R2.get(decodeURI(key));
let { readable, writable } = new FixedLengthStream(175104);
firmwareBin.body.pipeTo(writable);
return new Response(readable, firmwareBin);
Was this page helpful?