Krantho is in active development and not yet published to npm. Read what that means today.
esc

Search the documentation and product pages. Type “theme” to switch themes.

@krantho/media-local

The media file store on local disk, for development and for single servers with a persistent volume.

Intermediate

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-local

Configure#

krantho.config.ts
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' } },
})
SettingVariableDefault
media.local.dirKRANTHO_MEDIA_LOCAL_DIRpublic/uploads
media.local.urlPrefixKRANTHO_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#