Limiting file size uploaded from web-client / aborting request duing reading stream

For Workes & Pages, what is the name of the domain?

example.com

What is the issue or error you’re encountering

Limiting or aborting request when file size is bigger than limit I set

What steps have you taken to resolve the issue?

I’m currently using worker as a gateway receving files from front web-client.

I could limit the size at front (by getting size using blob)

but I want to also make a barear at cloudflare worker that could limit size of files being uploaded.

this is part of my code:

const uploadFile = (await request.formData()).get('file');
// use uploadFile.length to get size of file?
const putObject = await env.forzacdnBucket.put(temp_file_key, uploadFile);

My question is:

  1. is there a way to abort during reading streams if size exceeds limits?

  2. could limiting worker resource (ram, runtime) be the only solution?