Valet Key
Hand clients a short-lived, narrowly scoped token so they can upload or download files directly from storage, without streaming through your servers.
Description
Uploading a 2 GB video through your API means your servers hold the connection, buffer the bytes and pay for the bandwidth, just to pass them on to object storage. A valet key, like the key that only starts a car but doesn't open the boot, lets the client talk to storage directly instead.
The API checks that the user may upload, then creates a pre-signed URL: permission to write one specific object, for the next few minutes, nothing else. The client uploads straight to storage with it. Your API stays small and fast, and storage does what it's built for.
System design
Valet Key system design diagram
- Browser (client).
- Upload API (service): checks permission.
- Object storage (object storage).
- Scan & process (function): on upload event.
- Step 1: Browser → Upload API: may I upload video.mp4?.
- Step 2: Upload API → Browser: pre-signed URL (10 min).
- Step 3: Browser → Object storage: PUT file directly.
- Step 4: Object storage → Scan & process: object created.
- The browser asks the API for permission to upload a file.
- The API checks the user, then returns a pre-signed URL valid for 10 minutes for that one object key.
- The browser uploads the file straight to storage; none of its bytes pass through the API.
- Storage emits an event, and a function checks and processes the new file before it's used.
- AWS
- S3 pre-signed URLs (PUT/GET) and S3 event notifications to Lambda; CloudFront signed URLs for downloads.
- Azure
- Blob Storage shared access signatures (SAS) and Event Grid blob events.
- Google Cloud
- Cloud Storage signed URLs and Eventarc/Cloud Storage triggers.
When to use it
Use it when
- Clients upload or download large files: video, images, backups, exports.
- You want to remove your servers from the data path to save bandwidth, memory and cost.
- Access must be temporary and limited to specific objects.
Avoid it when
- Files must be scanned, transformed or validated before they're stored and you can't do that afterwards. Process them with storage events instead, or proxy them.
- The client can't be trusted with even limited direct access, or the storage can't issue scoped tokens.
Pitfalls
- Tokens that live too long or allow too much, such as write access to the whole bucket. Scope to one key, one operation and minutes.
- Not validating uploads afterwards. Use a storage event to check type, size and malware before the file is used.
- Leaking pre-signed URLs in logs or referrer headers. Treat them as secrets until they expire.
- Missing CORS configuration on the bucket, so browser uploads fail.
Alternatives
Proxying through the API
Choose it when files are small, or must be transformed in the request.
Protection proxy
Choose it when you need fine-grained checks on every access, not a one-off grant.
Static Content Hosting
Choose it when the files are public and the same for everyone; serve them from a CDN.