@krantho/media-local
The media file store on local disk, for development and for single servers with a persistent volume.
The media file store for media.provider: 'local'. It writes the bytes of uploaded media into one directory, which your framework serves as static files. Metadata, versions and folders live in your database; this package only stores files.
Install#
pnpm add @krantho/media-localConfigure#
import { defineKranthoConfig } from '@krantho/config'
export default defineKranthoConfig({
site: { domain: 'example.com', name: 'My Site', language: 'en', baseUrl: 'https://example.com' },
media: { provider: 'local', local: { dir: 'public/uploads', urlPrefix: '/uploads' } },
})| Setting | Variable | Default |
|---|---|---|
media.local.dir | KRANTHO_MEDIA_LOCAL_DIR | public/uploads |
media.local.urlPrefix | KRANTHO_MEDIA_LOCAL_URL_PREFIX | /uploads |
Next.js and Vite apps use public/uploads; SvelteKit apps use static/uploads. A file's URL is <urlPrefix>/<key>, so the prefix must be where your framework serves the directory. The image endpoint (/api/media/:id/image) reads the original through the store, not over HTTP.
How it stores files#
- Each file is written under a fresh, flat key such as
1712345678901-3f2a9c1b-hero-banner.jpg(a millisecond timestamp, a random part and the file name). Keys are never reused, so a file never changes once written. - Keys that contain a separator or start with a dot are rejected, so nothing can escape the directory.
- A replace writes a new file and deletes the old one; a delete removes the file.
You never construct the store yourself: the server loads it when media.provider is local. Media also needs SQLite or Postgres persistence, which keeps the metadata.
Next steps#
- Upload, organize and embed images: Media
- Manage media from the admin: @krantho/admin