createStorage
Build a storage instance with typed endpoints and a framework-agnostic request handler.
createStorage is the server entrypoint of vs3. It validates your options, builds endpoint context, and returns:
api: typed server-side endpoint callers (uploadUrl,downloadUrl, multipart endpoints).handler: WebRequest -> Responsehandler for framework routing.$Infer: inferred metadata types for client setup.
Basic Setup
import { aws, createStorage } from "vs3";
import { z } from "zod";
export const storage = createStorage({
bucket: "my-bucket",
adapter: aws({
region: "us-east-1",
credentials: {
accessKeyId: process.env.AWS_ACCESS_KEY_ID!,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!,
},
}),
metadataSchema: z.object({
userId: z.string(),
}),
});Returned API
storage.api returns the following endpoints:
uploadUrldownloadUrlmultipartCreatemultipartPresignPartsmultipartCompletemultipartAbort
These can be used on the server like this:
const upload = await storage.api.uploadUrl({
body: {
fileInfo: { name: "avatar.png", size: 1234, contentType: "image/png" },
metadata: { userId: "u_1" },
},
});For more information on the endpoints, see Endpoints.
Sharing Types with Client
Use storage.$Infer from your storage instance to keep server and client contracts synchronized:
import { createStorageClient } from "vs3/vue";
import type { storage } from "@/server/storage";
export const client = createStorageClient<typeof storage.$Infer>({});Warning
Use a type-only import to avoid bringing server code into browser bundles.
What createStorage Validates
At initialization, createStorage validates option formats such as maxFileSize and allowedFileTypes.
At runtime, endpoint boundaries still validate request input and metadata.
Next Steps
- Storage Options for full configuration.
- Endpoints for request/response contracts.
- Metadata Schemas for schema behavior.