@core-services/s3
v1.0.3
Published
A lightweight TypeScript wrapper built on top of AWS SDK v3 to simplify common S3 operations such as:
Downloads
18
Readme
S3Service
A lightweight TypeScript wrapper built on top of AWS SDK v3 to simplify common S3 operations such as:
Uploading files
Generating presigned upload URLs
Generating presigned download URLs
This service is ideal for backend APIs that need secure, temporary access to S3 objects.
🚀 Features
Direct file upload to S3
Generate presigned upload URL (for client-side uploads)
Generate presigned download URL (secure controlled downloads)
Customizable URL expiration
Written in TypeScript
📦 Installation npm install @core-services/s3
⚙️ Configuration
Create a config object using the S3ServiceConfig type:
interface S3ServiceConfig { region: string; accessKeyId: string; secretAccessKey: string; bucketName: string; expiresInSeconds?: number; }
🛠️ Usage
- Initialize the service import { S3Service } from "@core-services/s3";
const s3Service = new S3Service({ region: "ap-south-1", accessKeyId: process.env.AWS_ACCESS_KEY!, secretAccessKey: process.env.AWS_SECRET_KEY!, bucketName: "your-bucket-name", expiresInSeconds: 3600, // optional });
📬 Generate Presigned Upload URL
Useful when frontends/mobile apps upload directly to S3 without passing through your backend.
const { uploadUrl, key } = await s3Service.generateUploadUrl( "uploads/profile.png", "image/png" ); frontend can PUT file to uploadUrl
📥 Generate Presigned Download URL
const { downloadUrl } = await s3Service.generateDownloadUrl( "uploads/profile.png" );
- downloadUrl is valid only for configured expiration time
📤 Upload File to S3 (Server-Side)
await s3Service.uploadObject( "uploads/image.png", fileBuffer, "image/png" );
generateUploadUrl(key, contentType)
Creates a presigned PUT URL for client uploads. Returns { uploadUrl, key }.
generateDownloadUrl(key)
Creates a presigned GET URL for downloading files. Returns { downloadUrl }.
