Skip to content

Behavior Options ​

The FileStorage.FileStorage behavior wires upload handling into the FileStorage.FileStorage table's save/delete lifecycle. The plugin table attaches it automatically.

Only attach this behavior directly when you are creating a custom file storage table that saves upload entities itself:

php
$this->addBehavior('FileStorage.FileStorage', Configure::read('FileStorage.behaviorConfig'));

For uploads saved through another app table, such as Posts with a CoverImages association, attach FileStorage.FileAssociation to the app table instead. See Usage.

Options ​

OptionTypeDefaultDescription
fileStorageFileStoragerequiredThe FileStorage instance used to store files.
fileProcessorProcessorInterface|nullnullImage/file processor. null stores originals without processing.
fileValidatorstring|UploadValidatorInterface|nullnullValidator class or instance for upload validation.
fileFieldstring'file'The form field name that contains the uploaded file.
defaultStorageConfigstring'Local'Default storage adapter name.
ignoreEmptyFilebooltrueSkip processing when no file is uploaded.
dataTransformerDataTransformerInterface|nullnullEntity ↔ file-object transformer used by the image variant queue task.

Notes ​

fileField ​

By default the behavior looks for a 'file' field, so your form control should be named *.file. To use a different name, set fileField and name your control accordingly. See Usage.

fileProcessor ​

Pass an ImageProcessor (or a StackProcessor combining several processors) to generate image variants on upload. With null, upload saves use an empty processor stack; no variants are generated. The regeneration command and queue task require an actual processor. See Image variants and versioning.

fileValidator ​

A class name or instance implementing FileStorage\Model\Validation\UploadValidatorInterface. See Validation.

dataTransformer ​

Must be a FileStorage\FileStorage\DataTransformerInterface instance; anything else is ignored. When unset, a DataTransformer bound to the storage table is used. This is consumed by the image variant queue task — see The variant command.

Released under the MIT License.