Sending uploads through your own server means it has to receive, buffer and forward every byte. With large photos or videos, that's slow, expensive and a common cause of timeouts. Presigned URLs let the client upload straight to storage instead.

How it works

  1. The app asks your server for permission to upload a file.
  2. Your server checks the user is allowed to, then creates a short-lived signed URL for one specific object.
  3. The app uploads the file directly to that URL.
  4. The app tells your server the upload finished, and the server records it.

The storage credentials never leave the server; the client only gets a URL that works for a few minutes and one file.

Creating the URL on AWS

import { PutObjectCommand } from '@aws-sdk/client-s3'
import { getSignedUrl } from '@aws-sdk/s3-request-presigner'

const key = `uploads/${userId}/${crypto.randomUUID()}.jpg`
const url = await getSignedUrl(
  s3,
  new PutObjectCommand({ Bucket: BUCKET, Key: key, ContentType: 'image/jpeg' }),
  { expiresIn: 300 }
)

Google Cloud Storage has the same idea under the name "signed URLs".

Rules to keep it safe

  • Generate the object key on the server. Never let the client choose the path, or it could overwrite other people's files.
  • Limit type and size. Use a presigned POST policy if you need to enforce a maximum file size.
  • Keep expiry short. Five minutes is plenty for most uploads.
  • Keep the bucket private. Serve files through signed download URLs or a CDN, not a public bucket.
  • Configure CORS on the bucket for your site's origin, or browser uploads will fail.

After the upload

Process files in the background: resize images, scan for malware, extract video thumbnails. Storage events can trigger a function automatically when a new object arrives.