Looks like its the known issue with files that are too large to fit into cache, the workaround is to
Looks like its the known issue with files that are too large to fit into cache, the workaround is to bypass cache for these files using Cache Rules


/ as the valueput API. However, I keep getting "Provided readable stream must have a known length (request/response body or readable half of FixedLengthStream)" error. I have detailed a basic code example at https://gist.github.com/e332890143f40d1803a8d2aed089c517. Has anyone run into this and/or have a solution. Much appreciated!* to avoid them, but still seeing it intermittently. Only solution I've found so far is to "Disable cache" in the dev tools network tab, and that only works some of the time.

so this is basically a tradeoff between speed (less speed because of 1 extra API call), and cost (it will be cheaper because of Class A ops)profile-photos.my-domain.com that points to the R2 bucket.https://my-domain.com/resources/profile-photos/FNS-2304profile-photos subdomain with a fetch request:https://profile-photos.my-domain.com/cdn-cgi/image/width=256,quality=99,format=auto/FNS-2304https://my-domain.com/resources/profile-photos/FNS-2304?refresh=01HDQ5X4V6G1FKFNOT89WAR1SChttps://profile-photos.my-domain.com/cdn-cgi/image/width=256,quality=99,format=auto/FNS-2304?refresh=01HDQ5X4V6G1FKFNOT89WAR1SC

3be0c615e0158c0ba0110ba40f2de4db36e24c32 original.png
ca96b61d7c28300963e091080819f46221f34d4a downloaded.pngputprofile-photos.my-domain.comhttps://my-domain.com/resources/profile-photos/FNS-2304profile-photos// The slug in this URL example is `FNS-2304`
const slug = c.req.param("photos-slug");
const { refresh } = c.req.query();
const refreshString = refresh ? `?refresh=${refresh}` : "";
const photoUrl = `https://profile-photos.my-domain.com/cdn-cgi/image/width=256,quality=99,format=auto/${slug}${refreshString}`;
return fetch(photoUrl, {})https://profile-photos.my-domain.com/cdn-cgi/image/width=256,quality=99,format=auto/FNS-2304https://my-domain.com/resources/profile-photos/FNS-2304?refresh=01HDQ5X4V6G1FKFNOT89WAR1SChttps://profile-photos.my-domain.com/cdn-cgi/image/width=256,quality=99,format=auto/FNS-2304?refresh=01HDQ5X4V6G1FKFNOT89WAR1SCexport default <ExportedHandler<Environment>>{
async fetch(req, env) {
if (req.method === "POST") {
return Response.json(await env.R2.put("file", req.body));
}
return new Response((await env.R2.get("file"))?.body, {
headers: {
"content-type": "image/png"
}
});
}
}