๐๐ถ๐น๐ฒ ๐จ๐ฝ๐น๐ผ๐ฎ๐ฑ ๐๐ฟ๐ฐ๐ต๐ถ๐๐ฒ๐ฐ๐๐๐ฟ๐ฒ ๐๐ถ๐๐ต ๐ง๐ฎ๐ป๐ฆ๐๐ฎ๐ฐ๐ธ ๐ฆ๐๐ฎ๐ฟ๐ ๐ฎ๐ป๐ฑ ๐ฅ๐ฎ
File upload is a core feature for any SaaS. You need to handle profile images, large documents, and media libraries.
TanStack Start on Cloudflare Workers combined with R2 storage offers a fast and cheap way to build this.
Choose your method based on file size:
โข Small files (Under 5MB): Use multipart form uploads. Send files through TanStack Start server functions. This allows you to validate file types and sizes easily in one place.
โข Medium files (5MB to 100MB): Use presigned URLs. The browser uploads the file directly to R2. This saves your Worker from heavy work and reduces costs.
โข Large files (Over 100MB): Use chunked uploads. Break files into small pieces. This lets users pause and resume uploads without losing progress.
Why use Cloudflare R2?
The biggest advantage is zero egress fees. You do not pay when users download their files. This makes your costs predictable as you grow.
Production Checklist:
- Validate file types on both client and server.
- Enforce strict file size limits.
- Use UUIDs for filenames to keep paths safe.
- Set Content-Type headers explicitly.
- Use short expiration times for presigned URLs.
- Check user permissions before giving access to files.
- Limit upload rates per user to prevent abuse.
By matching your upload method to your file size, you build a system that stays fast and scales well.
Source: https://dev.to/feidou/file-upload-architecture-r2-multipart-and-streaming-in-tanstack-start-og8
Optional learning community: https://t.me/GyaanSetuAi