Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC Document changes to asset admin file size config #430

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions en/02_Developer_Guides/14_Files/01_File_Management.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,47 @@ UploadField options include:
- setFolderName() - Name of folder to upload into
- getValidator() - Get instance of validator to specify custom validation rules

## File upload limits {#upload-limits}

You can set the default file upload limits by configuring [`Upload_Validator.default_max_file_size`](api:SilverStripe\Assets\Upload_Validator->default_max_file_size).

File sizes can be represented as either integers (which is the file size in bytes) or an INI formatted string (e.g. 1b for 1 byte, 1k for 1 kilobyte, 1m for 1 megabyte, etc).

The configuration property accepts any of the following:

- A single value representing the maximum file size for *all* files
- An array, where the values are the maximum file size and the keys are one of:
- a category name from [`File.app_categories`](api:SilverStripe\Assets\File->app_categories), with square brackets around it (e.g. `'[images]'`)
- a file extension (e.g. `'jpg'`)
- an asterisk, which means "all file types which don't have a more specific configuration"

For example:

```yml
SilverStripe\Assets\Upload_Validator:
default_max_file_size:
'[image]': '500k' # Allow images up to 500KB
'doc': '2m' # Allow .doc files up to 2MB
'*' : '1m' # Allow everything else up to 1MB
```

You can also set upload limits per field by calling [`setAllowedMaxFileSize()`](api:SilverStripe\Assets\Upload_Validator::setAllowedMaxFileSize()) on the field's validator.

This method takes the same arguments as the `Upload_Validator.default_max_file_size` configuration.

```php
$field = UploadField::create('Banner');
$validator = $field->getValidator();
$validator->setAllowedMaxFileSize('2m');
```

If you want different file upload limits in the asset admin than you have in your upload fields, you can use the [`AssetAdmin.max_upload_size`](api:SilverStripe\AssetAdmin\Controller\AssetAdmin->max_upload_size) configuration property. This accepts values in the same format as `Upload_Validator.default_max_file_size`.

```yml
SilverStripe\AssetAdmin\Controller\AssetAdmin:
max_upload_size: '2m'
```

## File permissions {#permissions}

See [File Security](file_security).
Expand Down
1 change: 1 addition & 0 deletions en/04_Changelogs/5.2.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ This will now fail by throwing an exception, which means your form won't render

- A new [`SiteTree.hide_pagetypes`](api:SilverStripe\CMS\Model\SiteTree->hide_pagetypes) configuration property has been added. Unlike [`SiteTree.hide_ancestor`](api:SilverStripe\CMS\Model\SiteTree->hide_ancestor) (which has [now been deprecated](#api-silverstripe-cms)), this is an array. This allows you to define all page types that should be hidden in a single configuration property in your YAML configuration.
- You can now upload [Braille ASCII file format](https://en.wikipedia.org/wiki/Braille_ASCII) (`.brf`) files to the CMS without needing to modify the [allowed file types](/developer_guides/files/allowed_file_types/).
- The assets admin section now respects the [`Upload_Validator.default_max_file_size`](api:SilverStripe\Assets\Upload_Validator->default_max_file_size) configuration if [`AssetAdmin.max_upload_size`](api:SilverStripe\AssetAdmin\Controller\AssetAdmin->max_upload_size) has not been explicitly set for your project. Previously, asset admin would ignore `Upload_Validator.default_max_file_size` and just use the PHP `upload_max_filesize` ini configuration by default.

## API changes

Expand Down