Content API
The content API in Val provides helpers for defining content in your .val.ts files. The c object exported from your val.config contains c.define() and c.json(). Images and files are not constructed with a helper: they are plain objects carrying a path, described below.
c.define
The c.define() function is used to export content from Val module files. It takes three parameters: the module path, the schema, and the content data.
Signature
Parameters
modulePath- The file path of the module, relative to the project root (e.g.,/app/(main)/page.val.ts)schema- The schema definition, see schema typescontent- The actual content data that matches the schema
Basic example
Here's a simple example of using c.define() to export page content:
Images
An image is a plain object with a path and the metadata read off the file. There is no constructor to call - the same object can be written in a .val.ts and in a .val.json entry. Local images must be stored in the /public/val folder.
For schema definition, see the s.image() documentation.
Signature
Parameters
path- The file path to the image, relative to the project root (must be in/public/val), or the URL of a remote imageThe remaining fields are generated using the VS Code extension, the CLI or the UI:
width- The width of the image in pixelsheight- The height of the image in pixelsmimeType- The MIME type of the image (e.g.,image/jpeg,image/png)altandhotspotare yours to set -altis the alt text,hotspotis the point that must stay in frame when the image is cropped
Example
Here's how to define an image in a Val module:
Important notes
All images must be stored in the
/public/valfolderUse CLI or the VS Code extension to generate metadata
The width and height should match the actual dimensions of the image
The MIME type should accurately reflect the image format
Files
Generic files (such as videos, PDFs, or other documents) are plain objects too, carrying a path and a mimeType. Like images, local files must be stored in the public/val folder.
For schema definition, see the s.file() documentation.
Signature
Parameters
path- The file path to the file, relative to the project root (must be in/public/val), or the URL of a remote filemimeType- typically generated using the VS Code extension, the CLI or the UI:mimeType: the mime type of the file
Example with video
Here's how to define a video file:
Important notes
All files must be stored in the
/public/valfolderThe
acceptparameter ins.file()should match the MIME type of the fileYou can use wildcards like
video/*to accept multiple file types
Remote files
Remote files and images are stored on Val's remote server instead of in your Git repository. They are written exactly like local ones - remote-ness is read off the path: anything that is not under /public is remote. Remote files are immutable and managed by Val Build.
For detailed information on setting up and using remote files, see the Remote Files guide.
Signature
Parameters
path- The remote URL to the file on Val's serverThe metadata about the remote file is written alongside it, the same as for a local file:
mimeType- The MIME type of the file (e.g.,image/jpeg,video/mp4)
Example with remote image
Here's how to define a remote image. Note that the schema must include .remote() to enable remote files:
Example with remote video
Important notes
You must add
.remote()to your schema before pointing a field at a remote URLRemote files require connecting your project to Val Build
Remote file URLs are automatically generated when you upload files using the CLI or VS Code extension
You should not manually create remote URLs - use the Val tools to upload files
See Also
For complete setup instructions, uploading workflows, and best practices, see the Remote Files documentation.