Request Lifecycle
Understand how vs3 processes upload, download, and multipart requests from client to storage.
vs3 is built around one core idea: your app server should authorize and validate requests, while file bytes move directly between the client and your S3-compatible storage via presigned URLs.
Mental Model
For every operation, there are two layers:
- Control plane: your
vs3API (/upload-url,/download-url, multipart endpoints) validates input and returns presigned instructions. - Data plane: the browser uploads/downloads bytes directly to/from storage using those instructions.
This keeps your server lightweight and reduces failure modes in serverless deployments.
Single-Part Upload Flow
- The client calls
uploadFileor a framework hook/composable (useUpload). vs3client performs optional pre-flight validation (file size/type/name) if configured.- Client calls
POST /upload-urlon yourstorage.handler. - Global middleware chain runs first (
auth, signature verification, rate limit, CORS, timeout, logging, custom middleware). - Route logic validates:
- file info and filename
- allowed file types and max size
- metadata against
metadataSchema(if provided) - custom
contentValidators - optional
beforeUploadhook
vs3generates an object key (generateKeyor default key strategy).- Adapter creates presigned upload URL (+ optional headers, for example encryption headers).
- Client uploads the file directly to storage with XHR
PUT, tracks progress, then returns{ key, status, presignedUrl }.
Download Flow
- The client calls
downloadFileoruseDownload. - Client requests
POST /download-url. - Middleware chain runs.
- Route validates key and optional options, runs
beforeDownload, and checks object existence. - Adapter creates presigned download URL (+ optional headers).
- Client behavior depends on download mode:
"url": returns URL only."direct-download": fetches and triggers browser save."preview": opens in browser tab.
afterDownloadhook runs after URL generation.
Multipart Upload Flow
Use multipart for large files where reliability and resumability matter.
POST /multipart/createvalidates input and starts multipart session ->{ uploadId, key }.POST /multipart/presign-partsreturns presigned URLs for part numbers.- Client uploads parts in parallel with configurable
partSizeandconcurrency. - Client collects part ETags.
POST /multipart/completefinalizes upload.- On failure, client attempts best-effort cleanup with
POST /multipart/abort.
Where Middleware Fits
Middleware runs before endpoint logic, for every storage API request:
Client -> storage.handler
-> middleware chain
-> endpoint validation + hooks
-> adapter presign/object operation
-> responseMiddlewares can stop a request early (for example unauthorized request, invalid signature, or rate limit exceeded), which means endpoint logic never runs.
Why This Architecture Works
- Security: server controls authorization, validation, key generation, and signing.
- Performance: large files bypass your app server and stream directly to storage.
- Portability: adapters normalize AWS S3 and S3-compatible providers.
- Type safety: metadata contracts are shared between server and client from one schema.