server action or route handler for 12mb video uploads, two devs and a month Mutations
Users upload short screen recordings, typically 8-14 MB. Sending the File in FormData to a server action 413s at about a megabyte. I can raise bodySizeLimit but I am nervous about pushing 12 MB through a serverless function that also has a duration limit, and there are two of us with roughly a month before we have to show this working.
@wild_ferment · last mo. · 3 replies
Neither. The bytes should never touch your function.
Action A checks the session and returns a presigned PUT URL for R2 or S3. The browser PUTs the file straight to the bucket. Action B (or a bucket event) writes the row once the object exists. Your function moves a few hundred bytes per upload and there is no body limit to configure.
Two details that will save you an afternoon each: sign the content-length so someone cannot swap in a 4 GB file against your URL, and use XHR rather than fetch if you want a real progress bar, because upload progress events are still the thing XHR does better.
Reply
Report
@dax_darian · last mo.
And if these recordings get watched more than once, R2's egress pricing is the difference between a hosting line item and a hosting problem. We moved 900 GB/month of video out of S3 for that reason alone.
Reply
Report
@wild_ferment · last mo.
Expiry matters too — 15 minutes is plenty for a 12 MB upload. Long-lived signed URLs end up pasted into a chat somewhere and become an open write endpoint.
Reply
Report