UploadRejection
in package
Reasons why the Api did not store a newly uploaded item (gallery image, attachment).
The codes go to the caller in saveInfo.rejectedUploads
(SaveTrait::save()) and the admin builds the warning
"these files were not saved" from them (translated by code).
The save itself does not fail: accepted files are stored and rejected ones are only listed. Without the list a rejected image would vanish silently while the form reported plain success.
Static and stateless (like AttachmentFilePolicy).
Table of Contents
Constants
- REASON_DIMENSIONS : string = 'dimensions'
- The image is too large in pixels (ceiling {@see ImageUploadPolicy::MAX_PIXELS}, or memory).
- REASON_SAVE_FAILED : string = 'saveFailed'
- The file passed the checks but could not be written (disk/DB).
- REASON_SIZE : string = 'size'
- The file is larger than the upload limit of the record ({@see ImageUploadSizeLimit}).
- REASON_TYPE : string = 'type'
- The format/type is not accepted here (extension, content, SVG, video without a header).
- REASON_UNREADABLE : string = 'unreadable'
- The file cannot be read or decoded (corrupt, empty, rejected reference to a temporary file).
- REASONS : array<string|int, mixed> = [self::REASON_TYPE, self::REASON_DIMENSIONS, se...
- SAVE_INFO_KEY : string = 'rejectedUploads'
- Key in `saveInfo` (Result data of the save, see {@see \App\Core\Traits\Api\Presenters\SaveTrait}).
- MAX_NAME_LENGTH : int = 120
- Longest file name in a message (the rest is cut).
Methods
- buildMessage() : string|null
- Builds the "these files were not saved" warning from the rejected items, or `null` when nothing was rejected. The caller supplies the translation (`$translate(key, params)`); keys are relative to the `...uploaderDropzone.rejected` node of its domain: `message` (`%files%`), `item` (`%name%`, `%reason%`) and `reasons.<code>` (`%max%` is the dimension ceiling).
- displayName() : string
- Returns the file name for a message. A dropzone temporary file is named `<time>_<random>_<original>.<extension>` ({@see DropzoneTempRoot::buildFileName()}), but the user knows only the original name, so the prefix is stripped. The older shape without the original name (`<time>_<random>.<extension>`) stays as it is.
- fromImagePolicy() : string
- Converts a reason from {@see ImageUploadPolicy::getRejectionReason()} to a message code.
- fromSaveData() : array<int, array{name: string, reason: string}>
- Returns the rejected items from the save response (`Result::getData()['saveInfo']`), stripped of anything that is not `{name, reason}` with a known code; the input comes through the bridge, not from our own memory.
Constants
REASON_DIMENSIONS
The image is too large in pixels (ceiling {@see ImageUploadPolicy::MAX_PIXELS}, or memory).
public
string
REASON_DIMENSIONS
= 'dimensions'
REASON_SAVE_FAILED
The file passed the checks but could not be written (disk/DB).
public
string
REASON_SAVE_FAILED
= 'saveFailed'
REASON_SIZE
The file is larger than the upload limit of the record ({@see ImageUploadSizeLimit}).
public
string
REASON_SIZE
= 'size'
REASON_TYPE
The format/type is not accepted here (extension, content, SVG, video without a header).
public
string
REASON_TYPE
= 'type'
REASON_UNREADABLE
The file cannot be read or decoded (corrupt, empty, rejected reference to a temporary file).
public
string
REASON_UNREADABLE
= 'unreadable'
REASONS
public
array<string|int, mixed>
REASONS
= [self::REASON_TYPE, self::REASON_DIMENSIONS, self::REASON_SIZE, self::REASON_UNREADABLE, self::REASON_SAVE_FAILED]
SAVE_INFO_KEY
Key in `saveInfo` (Result data of the save, see {@see \App\Core\Traits\Api\Presenters\SaveTrait}).
public
string
SAVE_INFO_KEY
= 'rejectedUploads'
MAX_NAME_LENGTH
Longest file name in a message (the rest is cut).
private
int
MAX_NAME_LENGTH
= 120
Methods
buildMessage()
Builds the "these files were not saved" warning from the rejected items, or `null` when nothing was rejected. The caller supplies the translation (`$translate(key, params)`); keys are relative to the `...uploaderDropzone.rejected` node of its domain: `message` (`%files%`), `item` (`%name%`, `%reason%`) and `reasons.<code>` (`%max%` is the dimension ceiling).
public
static buildMessage(array<int, array{name: string, reason: string}> $rejected, callable(string, array<string, string>): string $translate) : string|null
Parameters
- $rejected : array<int, array{name: string, reason: string}>
- $translate : callable(string, array<string, string>): string
Return values
string|nulldisplayName()
Returns the file name for a message. A dropzone temporary file is named `<time>_<random>_<original>.<extension>` ({@see DropzoneTempRoot::buildFileName()}), but the user knows only the original name, so the prefix is stripped. The older shape without the original name (`<time>_<random>.<extension>`) stays as it is.
public
static displayName(mixed $name) : string
Parameters
- $name : mixed
Return values
stringfromImagePolicy()
Converts a reason from {@see ImageUploadPolicy::getRejectionReason()} to a message code.
public
static fromImagePolicy(string|null $policyReason) : string
Parameters
- $policyReason : string|null
Return values
stringfromSaveData()
Returns the rejected items from the save response (`Result::getData()['saveInfo']`), stripped of anything that is not `{name, reason}` with a known code; the input comes through the bridge, not from our own memory.
public
static fromSaveData(mixed $resultData) : array<int, array{name: string, reason: string}>
Parameters
- $resultData : mixed