Skip to content

Powered by Grav + Helios

Media

Media

Endpoints for managing media files attached to pages and site-level media.

Endpoints for managing media files attached to pages and site-level media.

List Page Media

GET /pages/{route}/media
List all media files for a page.

Parameters

Name Type Description
route required string The page route
JSON
{"data": [{"filename": "photo.jpg", "url": "/user/pages/blog/photo.jpg", "type": "image/jpeg", "size": 245000}]}

Response Codes

200 Success
401 Unauthorized
404 Page not found

Upload Page Media

POST /pages/{route}/media
Upload file(s) to a page via multipart form data.

Parameters

Name Type Description
route required string The page route
file required file File to upload (multipart/form-data)

Response Codes

201 File uploaded
401 Unauthorized
404 Page not found
422 Validation error (invalid file type or size)

Send the file as a multipart/form-data request rather than JSON. The Content-Type header should be set to multipart/form-data.

Delete Page Media

DELETE /pages/{route}/media/{filename}
Delete a media file from a page.

Parameters

Name Type Description
route required string The page route
filename required string The media filename to delete

Response Codes

204 File deleted
401 Unauthorized
404 Page or file not found

List Site Media

GET /media
List site-level media files and folders with pagination, subfolder browsing, search, and type filtering.

Parameters

Name Type Description
page optional integer Page number for pagination (default: 1)
per_page optional integer Number of results per page (default: 20, max: 100)
path optional string Subfolder path relative to the media root directory
search optional string Recursive filename search across all subfolders
type optional string Filter by media type: image, video, audio, or document

Response Codes

200 Success
401 Unauthorized

Returns media files and folders from the user/media directory. Supports browsing subfolders via the path parameter, recursive search via search, and filtering by file type via type. The response includes a folders array in the meta object listing immediate subdirectories at the current path.

Upload Site Media

POST /media
Upload files to the site-level media directory.

Parameters

Name Type Description
path optional string Subfolder path to upload into (created automatically if it does not exist)

Response Codes

201 Files uploaded successfully
401 Unauthorized
422 Validation error

Upload one or more files to the user/media directory. Use the path query parameter to upload into a subfolder. The request body should use multipart/form-data with a file field. Maximum upload size per file is 64 MB.

Delete Site Media

DELETE /media/{filename}
Delete a site-level media file.

Parameters

Name Type Description
filename required string The media filename to delete. May include a subfolder path (e.g. blog/hero.jpg).

Response Codes

204 File deleted
401 Unauthorized
404 File not found

Remove a file and its .meta.yaml sidecar (if present) from the user/media directory. The filename parameter supports subfolder paths.

Create Media Folder

POST /media/folders
Create a new folder in the site-level media directory.
JSON
{
  "path": "blog/2026"
}

Response Codes

201 Folder created
401 Unauthorized
422 Validation error or folder already exists

Create a new folder in the user/media directory. Parent directories are created automatically. The request body must include a path property with the relative folder path to create.

Delete Media Folder

DELETE /media/folders/{path}
Delete an empty folder from the site-level media directory.

Parameters

Name Type Description
path required string Folder path relative to the media root

Response Codes

204 Folder deleted
401 Unauthorized
404 Folder not found
422 Folder is not empty

Remove an empty folder from the user/media directory. The folder must contain no files or subdirectories.

Rename Site Media

POST /media/rename
Rename or move a media file within the site-level media directory.
JSON
{
  "from": "blog/hero.jpg",
  "to": "blog/banner.jpg"
}

Response Codes

200 File renamed
401 Unauthorized
404 Source file not found
422 Validation error or destination already exists

Rename a file or move it to a different folder within user/media. Both from and to are relative paths. The destination directory is created automatically if needed. Any .meta.yaml sidecar file is also moved.

Rename Media Folder

POST /media/folders/rename
Rename a folder within the site-level media directory.
JSON
{
  "from": "blog/old-name",
  "to": "blog/new-name"
}

Response Codes

200 Folder renamed
401 Unauthorized
404 Source folder not found
422 Validation error or destination already exists

Rename a folder within the user/media directory. All contents of the folder are preserved. Both from and to are relative paths from the media root.

Serve Thumbnail

GET /thumbnails/{file}
Serve a cached image thumbnail generated by the API's thumbnail service. Thumbnail filenames are hashes produced when media is serialized — Admin2 uses the URLs embedded in media responses rather than requesting thumbnails by path. Responses ship with `Cache-Control: public, max-age=31536000, immutable` so they are safe to cache for a year.

Parameters

Name Type Description
file required string Thumbnail filename (basename only).

Response Codes

200 Thumbnail served.
404 Thumbnail not found in cache.

Thumbnails are stored in cache://api/thumbnails/. They are generated lazily when a media item is serialized with a requested thumbnail size, so cold paths will return 404 until the parent media is fetched for the first time.