EncodedFile
API reference › FilePond › file › EncodedFile
Represents a file submitted by the FilePond File Encode plugin as a base64 JSON payload.
See also: https://pqina.nl/filepond/docs/api/plugins/file-encode/.
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$metadata readonly constructor | array<string, | FilePond item metadata, such as crop or poster. | EncodedFile |
$name readonly constructor | string | Client file name. | EncodedFile |
$type readonly constructor | string | Client MIME type as reported by the browser. | EncodedFile |
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
fromArray() static | Creates a file from a decoded File Encode payload. | EncodedFile |
fromInput() static | Creates the files submitted by one FilePond input. | EncodedFile |
fromJson() static | Creates a file from the JSON string submitted by the File Encode plugin. | EncodedFile |
getCropRectangle() | Returns the crop rectangle in source image pixels stored by the Cropper.js editor. | EncodedFile |
getData() | Returns the decoded binary content. | EncodedFile |
getExtension() | Returns the lowercase extension of the client file name. | EncodedFile |
getMimeType() | Returns the MIME type detected from the content rather than the client-reported $type. | EncodedFile |
getSize() | Returns the content size in bytes. | EncodedFile |
withData() | Returns a copy with different content, for example after server-side processing. | EncodedFile |
Method details
Section titled “Method details”fromArray()
Section titled “fromArray() ”public static function fromArray(array<array-key, mixed> $payload): selfCreates a file from a decoded File Encode payload.
Parameters
| Parameter | Type | Description |
|---|---|---|
$payload | array<array-key, | Payload with name and base64 data, plus optional type and metadata. |
Returns
self: File with decoded content.
Throws
InvalidArgumentException: if a key has an unexpected type ordatais not valid base64.
fromInput()
Section titled “fromInput() ”public static function fromInput(mixed $input): list<self>Creates the files submitted by one FilePond input.
Accepts the raw request value: a JSON string for single inputs, a list of JSON strings or decoded payloads
for multiple inputs, and null or empty values when nothing was selected.
Parameters
| Parameter | Type | Description |
|---|---|---|
$input | mixed | Request value of the FilePond input. |
Returns
list<self>: Decoded files, empty when nothing was submitted.
Throws
InvalidArgumentException: if the value or one of its entries is not a valid payload.
fromJson()
Section titled “fromJson() ”public static function fromJson(string $json): selfCreates a file from the JSON string submitted by the File Encode plugin.
Parameters
| Parameter | Type | Description |
|---|---|---|
$json | string | JSON object with name, type, data, and optional metadata. |
Returns
self: File with decoded content.
Throws
InvalidArgumentException: if the JSON is malformed or is not an object.
getCropRectangle()
Section titled “getCropRectangle() ”public function getCropRectangle(): array{x: int, y: int, width: int, height: int}|nullReturns the crop rectangle in source image pixels stored by the Cropper.js editor.
Returns
array{x: int, y: int, width: int, height: int}|null: Rectangle, or null when the file was not cropped.
getData()
Section titled “getData() ”public function getData(): stringReturns the decoded binary content.
Returns
string: File content.
getExtension()
Section titled “getExtension() ”public function getExtension(): stringReturns the lowercase extension of the client file name.
Returns
string: Extension without the dot, or an empty string.
getMimeType()
Section titled “getMimeType() ”public function getMimeType(): stringReturns the MIME type detected from the content rather than the client-reported $type.
Returns
string: Detected MIME type, or application/octet-stream when detection fails.
getSize()
Section titled “getSize() ”public function getSize(): intReturns the content size in bytes.
Returns
int: Size in bytes.
withData()
Section titled “withData() ”public function withData(string $data, string|null $type = null, string|null $name = null): selfReturns a copy with different content, for example after server-side processing.
Parameters
| Parameter | Type | Description |
|---|---|---|
$data | string | New binary content. |
$type | string| | New client MIME type, or null to keep the current one. |
$name | string| | New client file name, or null to keep the current one. |
Returns
self: Copy with the replaced values.