@stack-upload-orchestrator/storage-local
v0.1.1
Published
Local-disk storage adapter for @stack-upload-orchestrator/node
Readme
@stack-upload-orchestrator/storage-local
Local-disk storage adapter for @stack-upload-orchestrator/node.
Streams uploaded files directly to the filesystem. Suitable for development and single-server deployments.
Installation
npm install @stack-upload-orchestrator/storage-local @stack-upload-orchestrator/nodeUsage
import { LocalStorage } from '@stack-upload-orchestrator/storage-local';
const storage = new LocalStorage({
destination: './public/uploads',
baseUrl: 'https://example.com/uploads',
});Pass it to any handler:
// With Next.js
import { createUploadHandler } from '@stack-upload-orchestrator/next';
export const POST = createUploadHandler({ storage });
// With Node.js / Express
import { handleUpload } from '@stack-upload-orchestrator/node';
const files = await handleUpload(req, { storage });LocalStorage
new LocalStorage(options: LocalStorageOptions)Options
| Option | Type | Description |
|---|---|---|
| destination | string | Absolute path to the directory where files are stored (created if it doesn't exist) |
| baseUrl | string | Base URL prepended to the filename in UploadResult.url. Defaults to file://<destination> |
| filename | (meta) => string \| Promise<string> | Custom filename resolver. Defaults to <uuid><original-extension> |
Methods
| Method | Description |
|---|---|
| upload(stream, meta) | Streams the file to disk and returns UploadResult |
| delete(fileId) | Deletes the file by its stored filename |
Custom filename
const storage = new LocalStorage({
destination: './uploads',
filename: (meta) => `${Date.now()}-${meta.filename}`,
});UploadResult
{
url: string; // baseUrl + "/" + filename
fileId: string; // stored filename (use this for delete)
name: string; // original filename from the upload
size: number; // bytes written to disk
type: string; // MIME type
}License
MIT
