A minimal guide on how to use the built-in S3 storage system.
The storage feature works with any S3 compatible bucket right away. Set environment variables and start uploading, replacing, listing files, and generating public URLs through a simple API.
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
S3_ENDPOINT=
S3_REGION=
S3_BUCKET_NAME=
VITE_S3_PUBLIC_URL=Once these are filled in, storage becomes ready to use across your project.
Use the provided API wherever you need to store user uploads (eg: avatars, documents, images, xxx).
import { storageAPI } from "@/features/storage/storageAPI"
storageAPI.uploadFile({
Key: 'path/inside/bucket', // New S3 path/filename
Body: <file-content>, // File content (string, Buffer, Stream, or Blob)
ContentType: <mime-type> // File's MIME type (e.g., 'image/jpeg')
})File, Blob, buffer, or base64 turned into buffer)Key (ex: "avatars/user123.png")Body and set the correct ContentTypeThis is the only function you need to upload files anywhere in your application.
storageAPI.replaceFile({
Key: 'new/path',
Body: <file-content>,
ContentType: <mime-type>,
oldKey: 'old/path'
})Useful for profile updates and similar flows.
oldKey to automatically remove the previous fileThe API handles both deletion + upload for you.
storageHelper.publicUrl("path/to/file");storageAPI.listFiles("folder-prefix/");storageAPI.deleteFile("path/to/file");This is commonly/mainly used for admin tools or cleanup operations.
The project also includes a utility that you can utilize to reset and seed your storage quickly.
It is also helpful for if you want to automatically populate initial files in your S3 bucket instead of uploading them manually.
What it does:
avatars/ folderThis allows you to keep the storage consistent and makes initial deployments easier.
You get:
You don't need to interact with the underlying S3 commands, everything is abstracted to simple/easy functions.
You only need to:
storageAPI functions:
uploadFilereplaceFilelistFilesdeleteFilestorageHelper.publicUrl to generate public linksThings like configuration, S3 commands, MIME detection are handled behind the scenes.