Back to ✨ Feature Scaffolding

Handle File Uploads (S3)

AWSS3Uploads
---
description: Setup secure file uploads to AWS S3
---

1. **Install AWS SDK**:
- Install the S3 client and presigner.
// turbo
- Run npm install @aws-sdk/client-s3 @aws-sdk/s3-request-presigner

2. **Create Presigned URL (Server Action)**:
- Generate a presigned URL on the server for direct client uploads.
'use server'
import { S3Client, PutObjectCommand } from '@aws-sdk/client-s3';
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';

const s3Client = new S3Client({
region: process.env.AWS_REGION!,
credentials: {
accessKeyId: process.env.AWS_ACCESS_KEY_ID!,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!,
},
});

export async function getUploadUrl(filename: string, contentType: string) {
const command = new PutObjectCommand({
Bucket: process.env.AWS_BUCKET_NAME!,
Key: uploads/${Date.now()}-${filename},
ContentType: contentType,
});

const url = await getSignedUrl(s3Client, command, { expiresIn: 3600 });
return url;
}


3. **Upload from Client**:
- Use the presigned URL to upload directly to S3.
async function handleUpload(file: File) {
const uploadUrl = await getUploadUrl(file.name, file.type);
await fetch(uploadUrl, {
method: 'PUT',
body: file,
headers: { 'Content-Type': file.type },
});
}


4. **Pro Tips**:
- Configure CORS on your S3 bucket: allow PUT from your domain.
- Use presigned URLs to avoid exposing AWS credentials to clients.
- Set expiration times (3600s = 1 hour) to limit upload window.
By Antigravity Team

How to Use This Workflow

Option A: Project-Specific (Recommended)

  1. Click "Download" above
  2. In your project, create the directory: .agent/workflows/
  3. Save the file as handle-file-uploads-aws-s3-presigned-urls.md
  4. In Antigravity, type /handle_file_uploads_aws_s3_presigned_urls or just describe what you want to do

Learn more about workflows →

Related Workflows

Recommended Rules

View more rules →

Recommended MCP Servers

View more MCP servers →

Take It Further

Maximize your productivity with these powerful resources

📋

Define Your Standards

Set up coding standards to ensure this workflow produces consistent, high-quality results.

Browse Rules Library
📖

Master Workflows

Learn how to create custom workflows, use Turbo Mode, and build your automation library.

Complete Guide