Working with Files
Files in Val
Val supports generic file uploads for any file type, including videos, PDFs, audio files, and more. Files work similarly to images, but with more flexibility in file types.
Key Differences from Images
The main differences when working with files instead of images:
Use
s.file()instead ofs.image()in your schemaUse
s.file()instead ofs.image()for non-image files - the content object looks the same, but carries onlypathandmimeTypeYou can specify accepted file types with the
acceptoption (e.g.,accept: 'video/*',accept: '.pdf,.doc')When you use
accept: 'video/*', Val Studio will render it as a video with preview
Schema and Content
Collections: many files in one module
s.file() defines one field. For a shared pool of files - a document library, a set of downloads - use s.files() instead. Note the plural: s.files() defines an entire module rather than a field, the same way s.images() does for images.
A collection is a record keyed by file path, whose values carry the mimeType Val read off each file. Both accept and directory are required, and no two collections may share a directory.
Picking from a collection
Pass the collection module to s.file() and the field becomes a picker for it, exactly as s.image(galleryVal) does for images. The value is then only the path: the mimeType is stored once, in the collection, so a field that repeats it is a validation error.
Where to find collections in Val Studio
Like image galleries, collections are listed under Media in Val Studio rather than in the Explorer file tree.
Using Files in Components
When using files in your components, access the URL using the .url property:
Basic usage
Using val.attrs and val.raw
For advanced use cases where you need to control visual editing attributes, you can use val.attrs() and val.raw() with the file URL:
More Information
For detailed information about adding metadata, working with remote files, and using the CLI or VS Code extension, see the Images Guide. The workflow is identical - just use s.file() instead of s.image().
For a comprehensive guide on working specifically with videos, see the Videos Guide.