Skip to main content
Use FlexMedia in application services, controllers, commands and jobs. Examples use an application-owned $source, $intent or $receipt when introduced in an earlier example; disk names must exist in config/filesystems.php.

Common imports

Local file

The source path is read, not moved or deleted. Choose a safe destination directory; filenames cannot contain path traversal or multiple path segments.

HTTP request upload

MediaSource::upload() accepts a Livewire TemporaryUploadedFile. For Laravel’s ordinary request UploadedFile, use its local path:
Validate presence and the request’s rules before this example. Media OS independently validates the inspected bytes at permanent storage.

Livewire temporary upload

Borrowed stream

Media OS reads from the stream’s current position. It does not rewind or close a borrowed stream. Close it in your own finally block.

Copy between configured disks

Small inline file

Inline sources have a separate 4 MiB ceiling. Use a stream or path for larger files.

Exact filename

Existing destinations are rejected rather than overwritten. Omit filename for a generated destination. A chosen filename does not bypass MIME validation.

File policy

MIME types come from content inspection. An empty MIME list allows any inspected type within the byte policy; use an allow-list for a restricted workflow.

Attach application context

metadata is context for your policies, processors and listeners. It is not automatically a new database column. Its JSON representation is limited to 64 KiB.

Inspect without storing

Inspection applies policy, configured processors and the pre-write scan. The returned snapshot belongs to your caller; close it after use.

Read the storage result

A receipt describes an object; possession of one does not grant access to it. Use receipts retained by your application, with the same record and policy context used at storage.

Private temporary URL

Returns null when the adapter cannot provide the requested URL. A failed private signing operation does not become a public link. Configure temporary URL support on your disk or provide your own signing resolver.

Verify a saved file

Rechecks persisted bytes and policy, including the post-write scan. Integrity verification defaults to true; the optional third argument controls checksum comparison for that explicit verification call.

Delete an owned file

For an image bundle, use FlexMedia::images()->delete($bundle) so all owned variants are included. For queued variants, cancel their plan before deleting the original.

Reject before publication

Throwing rejects the new write and attempts to remove files created by that operation. A finalizer is for acceptance checks. Transform content with a processor, not by mutating an already measured file.

Handle rejection

Use stable reason codes such as size_rejected and type_rejected for your application’s messages. Keep exception chains and storage credentials out of end-user messages.

API reference

compensate() is intended for rejection handling, including configured quarantine. Use ordinary delete() for a customer’s deliberate removal.

Write options reference

operationId correlates operations; it does not make a direct store call an idempotent retry. Use staging receipts for retry recovery.

Policy options reference

A policy must have a positive maximum and a minimum between zero and that maximum. Required scanning cannot disable either scan boundary.

Copy a write with a different policy

Correlate application operations

Import Illuminate\Support\Str. withoutProcessors() produces a write with the same other options but an empty processor list; only use it when deliberately operating on an already processed source.
Last modified on October 16, 2026