Validation
The AttachmentField accepts the standard Filament validation rules. Look for the complete list in Filament's documentation.
Furthermore, the package also provides additional validation rules.
Restricting specific MIME-types
The AttachmentField can be restricted to specific MIME-types by calling the mime method:
Tip
The method also accepts wildcards such as 'image/*'.
AttachmentField::make('featured_image')->mime('image/png')MIME-specific
The AttachmentField provides the ability to filter by different file types by using the following methods:
AttachmentField::make('featured_image')->image()
AttachmentField::make('featured_image')->video()
AttachmentField::make('featured_image')->text()By using these methods, you can increase readability and make it easier to oversee the use of specific file types.
Restricting extensions
Some file types have no reliable MIME-type, such as .vtt and .srt captions. Restrict those by extension instead:
AttachmentField::make('captions')->extensions(['vtt', 'srt'])Extensions are matched case-insensitively, both when picking from the library and when uploading. They can be combined with a MIME-type filter.
Multiple attachments
The AttachmentField can accept multiple attachments by calling the multiple method:
AttachmentField::make('featured_image')->multiple()It is also possible to specify the minimum and maximum amount of allowed files:
AttachmentField::make('featured_image')->minFiles(5)
AttachmentField::make('featured_image')->maxFiles(10)SVG sanitization
SVG uploads are sanitized before they are stored. Scripts, event handlers and references to remote resources are stripped from the file, so the contents saved to disk may differ from what was uploaded. An SVG that cannot be parsed is rejected with a validation error rather than stored as-is.
This applies to every upload route in the package: files dropped onto the browser or an
AttachmentField, and files supplied through the replace action.
