Secure File Uploads in Node.js with Cloud Storage

Presigned URLs, validation and private buckets: uploads that do not overload your server or expose your files.
Streaming large files through your API server wastes memory and bandwidth. Uploading directly to cloud storage with presigned URLs is simpler and safer.
The presigned URL flow
- The client asks your API for an upload URL, sending the file name, type and size.
- Your API validates the request and returns a short-lived presigned URL for a specific key.
- The client uploads directly to storage.
- The client tells your API the upload finished, and the API records it.
Validate before signing
- Allow-list content types, such as image/png and application/pdf.
- Enforce a maximum size in the signed policy, not only in the UI.
- Generate the storage key on the server; never trust a client-supplied path.
Keep buckets private
Store uploads in a private bucket and serve them through short-lived signed download URLs or a CDN with access rules. Public buckets are one of the most common sources of data leaks.
Process after upload
Resize images, scan files and extract metadata in a background job triggered after the upload is confirmed. The user gets a fast response and heavy work happens off the request path.









