media defines the libraries used by image fields, file fields and images in rich text. Uploads are committed to the site's GitHub repository, like any other file. Each library has two paths:

  • input: the folder in the repository where files are stored.
  • output: the public path the site serves them from, which is what gets written into content.
media:
  input: public/uploads
  output: /uploads

With this, uploading photo.jpg stores public/uploads/photo.jpg and saves /uploads/photo.jpg in the field. The site must serve that path; SP CMS doesn't configure it. In an Astro site, files in public/ are served from the root, so public/uploads becomes /uploads. See set up a site for help finding the values.

Each upload can be up to 20 MB.

Shorthand

A string sets input, and output becomes the same path with a leading /:

media: uploads # input: uploads, output: /uploads

Multiple libraries

Use a list to give different content different folders or file types. Each library needs a unique name:

media:
  - name: images
    label: Images
    icon: Image01
    input: public/images
    output: /images
    categories: [image]
    rename: safe
  - name: documents
    label: Documents
    input: public/files
    output: /files
    categories: [document, spreadsheet]

Fields use the first library unless they pick one with options.media:

- name: brochure
  type: file
  options:
    media: documents

Keys

Key Description
input Required. Repository folder, without a leading or trailing /.
output Required. Public path written into content, without a trailing /. Can be a full URL.
name Required in a list. Unique ID referenced by options.media. It may match a content name.
label Name shown in the sidebar.
icon A Hugeicons name for the sidebar, such as Image01.
categories Allowed file types by category: image, document, video, audio, compressed, code, font, spreadsheet.
extensions Allowed extensions, such as [jpg, png, webp]. Overrides categories.
rename Rename uploads: false keeps the original name (default), true or safe makes it URL-safe, random generates a unique name.
commit Commit message templates and identity for this library. See settings.
actions Action buttons on the library page. See actions.

Without categories or extensions, a library accepts any file type.

Field settings

Image, file and rich-text fields can set their own allowed types and rename:

  • extensions or categories on a field narrow what the library allows. They can't add a type the library doesn't accept.
  • Without them, an image field accepts the library's types, or image types if the library has no restriction. Images in rich text only ever accept image types.
  • rename on a field replaces the library's setting for uploads made from that field.

A saved image or file value must point inside its library. SP CMS rejects paths outside the library's folder, including links to other websites.