AWS Builder Center

Stop Routing File Uploads Through Your Server. Use S3 Presigned URLs Instead.

If your app lets users upload files, profile pictures, documents, attachments, there's a good chance the upload flow looks like this: client sends the file to your backend, backend forwards it to S3. It works, but it means your server is spending compute and bandwidth just relaying bytes it doesn't need to touch. S3 presigned URLs fix this. They let your backend generate a temporary, permission-scoped URL that the client uses to upload (or download) directly to S3, no file ever passes through your server.

I am a part-time freelancer Full stack Developer and Learning about AWS actively



How it works
  1. The client asks your backend for permission to upload a file.
  1. Your backend generates a presigned URL using the AWS SDK, scoped to a specific bucket, key, content type, and expiry time.
  1. The client uploads the file directly to S3 using that URL.
  1. Your backend never sees the file bytes, only the request to generate the URL.

A minimal example (Node.js)

import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";

const s3 = new S3Client({ region: "us-east-1" });

export async function getUploadUrl(key, contentType) {
const command = new PutObjectCommand({
Bucket: "my-app-uploads",
Key: key,
ContentType: contentType,
});

return getSignedUrl(s3, command, { expiresIn: 300 }); // 5 minutes
}

The client then does a plain  PUT  request to that URL with the file body. No AWS credentials ever reach the browser.

Things worth getting right

  • Scope the key server-side. Don't let the client dictate the S3 key freely, generate it yourself (e.g.  uploads/{userId}/{uuid}-{filename} ) to avoid overwrites or path traversal.
  • Set a short expiry. Five to fifteen minutes is usually enough. Long-lived URLs are a liability if leaked.
  • Validate  ContentType  and size. Presigned URLs can enforce content type, but size limits need a bucket policy or  Content-Length-Range  condition if you're using POST-based uploads.
  • Use  PutObjectCommand  for PUT uploads, or  createPresignedPost  for form-based uploads if you need to enforce more conditions (like max file size) at signing time.

Why it's worth the switch

For anything beyond toy projects, this pattern removes a real bottleneck. Your server stops being a proxy for file traffic, uploads scale independently of your app instances, and you get cleaner separation between "who can upload" (your backend's job) and "moving the bytes" (S3's job).
It's a small change with a real gain in reliability and cost, and it took me one afternoon to migrate an existing upload flow to this once I understood the pattern.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article