Search by

codepulse2020 / filament-media-browser

haosheng

A standalone Filament media browser powered by Laravel Storage — no database required.

Package info

github.com/codepulse2020/filament-media-browser

pkg:composer/codepulse2020/filament-media-browser

Statistics

Installs: 12

Dependents: 0

Suggesters: 1

Stars: 0

Open Issues: 0

v2.1.1 2026-11-30 04:09 UTC

This package is auto-updated.

Last update: 2026-11-30 04:10:05 UTC


README

Latest Version on Packagist Total Downloads

A standalone Filament media browser powered by Laravel Storage for browsing and codepulse2020/media-upload for uploads. No database is required.

Features

  • Browse the files of codepulse2020/media-upload profiles: each profile's disk and directory decide where files live
  • Upload and delete files; create folders and delete empty folders inside a profile's directory
  • Breadcrumb navigation with subfolder support
  • Filter by media type (image, video/audio, or all files)
  • Search files by name
  • Filename sanitization and collision handling
  • Path traversal protection
  • Authentication guard on all operations
  • Dark mode support
  • Integrates with Filament 3, 4 and 5 panels and Livewire components

Installation

composer require codepulse2020/filament-media-browser

Publish the config file:

php artisan vendor:publish --tag="filament-media-browser-config"

For a Filament 3 custom theme, add the package views to the Tailwind 3 content array:

// tailwind.config.js
content: [
    // ...existing paths
    './vendor/codepulse2020/filament-media-browser/resources/views/**/*.blade.php',
]

For Filament 4 or 5 with a Tailwind 4 custom theme, add the plugin views as a source. Adjust the relative path to match your theme file:

@source '../../../../vendor/codepulse2020/filament-media-browser/resources/views/**/*.blade.php';

Then rebuild your theme assets:

npm run build

Make sure the storage disk is linked (for the public disk):

php artisan storage:link

Configuration

// config/filament-media-browser.php

return [
    // media-upload profile opened when a field does not call ->profile().
    'profile' => 'filament-media-browser-public',

    // Every other profile a field or event may open, with optional Gate abilities.
    'profiles' => [
        'post-images' => [],
        'hero-images' => [
            'read_ability' => 'view-hero-media',
            'write_ability' => 'manage-hero-media',
        ],
    ],

    // Public disks use public URLs. A disk with private visibility uses short-lived previews.
    'preview_modes' => ['public' => 'public', 's3' => 'temporary'],
    'preview_ttl' => 5,
    'listing_limit' => 100,
    'selection_limit' => 50,

    // null uses the current panel guard or the application guard.
    'guard' => null,

    // Optional Gate ability that must pass to use the browser (null = disabled).
    'authorization' => null,

    // Output format: true = Storage::url(), false = relative path
    'store_as_url' => true,
];

The browser never chooses a disk or directory itself. Each profile in config/media-upload.php defines both, and the browser opens the profile's disk at its effective directory (for public profiles this includes the upload package's public/ prefix, e.g. public/media). Only the default profile and the keys of profiles can be opened; any other name from the frontend is denied, as is a profile media-upload cannot resolve or whose disk is not configured. Profile abilities run in addition to the package-wide ability. Write operations require the read ability and any configured write ability. Use the panel and media abilities to enforce account status, role, and tenant access.

Roots of the listed profiles on the same disk must be disjoint, so one profile's Gate cannot be bypassed through another profile's root. A custom Gate receives the user and one context array containing profile, disk and directory.

Disk capabilities

Disk Listing Previews Empty folders
Local filesystem Bounded folder window Public URLs for public disks, or a compatible temporary URL builder or host resolver Supported
Laravel AWS S3 driver Native continuation pages Public or temporary URLs according to the disk policy Folder markers, when allowed by the backend
Other Laravel adapters Bounded folder window Depends on URL capability or host resolver Opt in through the empty_folders map after verifying adapter behavior

AWS S3 and S3-compatible services use the host application's Laravel S3 configuration. The host installs league/flysystem-aws-s3-v3 for this driver. The automated S3 integration uses AWS Emulator on a disposable runner. Private S3 writes omit Flysystem's implicit canned ACL so they work with bucket-owner-enforced buckets. Explicit public visibility or an explicit ACL disk option still applies. Verify AWS S3 and Alibaba Cloud OSS with the actual endpoint, addressing style, ACL and preview behavior before depending on those combinations in production. A native OSS adapter follows the generic adapter path.

Search covers the loaded page or window. For native S3 pagination, use Next page to continue searching the folder. The sidebar loads child folders on expansion. Set preview_url_resolver to a host-provided invokable service class if your application needs to issue an authorized preview route. An already issued presigned URL remains usable until it expires. An authorized route can recheck access on every fetch.

New uploads use the filename configured in media-upload (a ULID by default). Existing files keep their stored paths. Configure a separate download origin or appropriate content-serving rules for public uploads.

Upload processing with codepulse2020/media-upload

codepulse2020/media-upload handles validation, processing, naming and storage for every upload. It is installed from Packagist as a dependency of this package (^1.1). For development against a local checkout, use a Composer path repository in the root project. If you use its private profiles with proxy delivery, register its signed file route in your routes file with MediaUpload::routes(); see the media-upload README.

The built-in filament-media-browser-public profile stores on the public disk under public/media. It accepts JPEG, PNG, WebP and GIF up to 10 MB each. Define a profile with the same name in config/media-upload.php to change it.

Define a dedicated profile in config/media-upload.php:

'profiles' => [
    // Add alongside your existing profiles.
    'browser-images' => [
        'disk' => 'local',
        'directory' => 'uploads/browser',
        'visibility' => 'private',
        'mimes' => ['image/jpeg', 'image/png', 'image/webp'],
        'max_size' => 10240, // KB
    ],
],

List it in the browser config:

// config/filament-media-browser.php
'profiles' => [
    'browser-images' => [
        'read_ability' => 'view-media',
        'write_ability' => 'manage-media',
    ],
],

Uploads run synchronously into the open folder, below which media-upload adds the profile's date folder (date_directory, Y/m by default), e.g. uploads/browser/products/{year}/{month}/{ulid}.jpg when products is open; the browser then opens that folder. Uploading while a date folder is open stores in its parent folder rather than nesting date folders, and with date_directory set to null files go straight into the open folder. Folder names may contain only letters, digits, - and _ to receive uploads, and media-upload refuses folders that would cross its public/private boundary. Folders can be created anywhere inside the profile's directory, but only empty folders can be deleted; delete the files inside first. Files are deleted through media-upload, so content-addressed files (filename.generator = hash) that may be shared with other uploads cannot be deleted from the browser. A profile hook that moves a file outside the profile's directory makes the upload fail. The profile is the only place that defines accepted types and size: the file picker's accept list and the rejection messages come from it, narrowed to the browser's media type so a file the listing would hide is never stored (the upload button is hidden when nothing remains), and unless you configure livewire.temporary_file_upload.rules yourself, the browser raises Livewire's temporary upload size limit (12 MB by default) to the largest profile it uses. If you do configure those rules, keep their max at or above your profiles' max_size. PHP's upload_max_filesize and post_max_size still cap every request. Public profiles use the upload package's public prefix and accept only raster images that it re-encodes.

If the profile is invalid or the upload is rejected, no file is written to the media library. Listing, preview URLs, selection and deletion remain the browser's responsibility. Use ->storeReference() (or ->storePath() for a fixed disk) for private files and configure a private preview resolver if the disk cannot issue temporary URLs. Do not point a browsable profile at pending or quarantine paths. If the upload package uses hash-based deduplication, keep those profiles out of the browser because a file may be shared by multiple records.

Upgrading. Replace haosheng0211/filament-media-browser with codepulse2020/filament-media-browser and the MrJin\FilamentMediaBrowser namespace with CodePulse2020\FilamentMediaBrowser, including class names stored in your data and the vendor/ path in Tailwind sources. disk, directory, upload_profile, allowed_disks and scopes are removed from the browser config, as are ->mediaDisk() and ->mediaDirectory() on fields and the disk / directory event parameters. An event that still sends them without a profile is refused with a 403. Define a media-upload profile for each location, list it under profiles (moving any scope abilities there), and use ->profile() or the profile event parameter. Existing files are not moved and stored URLs are not rewritten, but only folders inside a profile's directory can be browsed. The previous default root was media; files there are no longer reachable from the browser unless a profile's effective directory covers them. Move any custom MIME, size or extension rules from the old accepted_file_types, max_file_size and blocked_extensions settings into config/media-upload.php. Non-image uploads, including audio and video, require a private profile and explicit MIME mappings for formats not already supported by the upload package.

Usage

MediaPicker Field

A dedicated form field with square card previews, replace and remove buttons. Both single and multiple modes use the same grid layout with 1:1 aspect ratio cards. Stores the selected file's URL as a string (single) or array of strings (multiple) by default.

use CodePulse2020\FilamentMediaBrowser\Forms\Components\MediaPicker;

// Basic usage — single image picker with preview
MediaPicker::make('featured_image');

// Multiple images (gallery)
MediaPicker::make('gallery')
    ->multiple()
    ->maxItems(10)
    ->reorderable(); // drag-to-reorder, enabled by default

// File picker (no image preview, shows path instead)
MediaPicker::make('attachment')
    ->mediaType('file');

// Another media-upload profile (listed in filament-media-browser.profiles)
MediaPicker::make('hero_image')
    ->profile('hero-images')
    ->storeReference();

// Store relative path instead of URL
MediaPicker::make('document')
    ->storePath();

// Custom grid columns (default: 5, fewer = larger cards)
MediaPicker::make('hero')
    ->gridColumns(3);

Stored value:

  • Single mode: string (e.g. /storage/media/photo.jpg) — use a string column
  • Multiple mode: array of strings — use a json column with ->cast('array') on the model
  • Public URL is the default output. For private disks use ->storePath() when the disk is fixed by the field, or ->storeReference() to keep the disk and key together (e.g. media://s3/uploads/heroes/photo.jpg). Preview URLs are resolved separately.

Available Methods

Method Description
->multiple(bool) Enable multi-select mode
->maxItems(int) Maximum number of files (multiple mode)
->reorderable(bool) Enable drag-to-reorder (multiple mode, default: true)
->mediaType(string) 'image', 'media', or 'file'. Default: derived from the profile (image for image-only, media for video/audio-only, otherwise file)
->profile(string) media-upload profile to browse and upload with (default: config profile)
->storeAsUrl(bool) Store as Storage::url() output (default: true)
->storePath(bool) Store as relative path (e.g. media/photo.jpg)
->storeReference(bool) Store the disk and key using the media:// format
->gridColumns(int) Number of columns in the preview grid (default: 5)

With Filament Forms TinyMCE

filament-forms-tinymce opens this browser from its file picker. Choosing a profile needs a release with ->mediaProfile(); fields without it open the default profile.

use CodePulse2020\FilamentFormsTinymce\TinyMceEditor;

TinyMceEditor::make('content');

// Another media-upload profile (listed in filament-media-browser.profiles)
TinyMceEditor::make('content')
    ->mediaProfile('post-images');

// Disable the file browser
TinyMceEditor::make('content')
    ->fileBrowser(false);

Standalone Usage via Events

The media browser communicates via Livewire events, so you can integrate it with any component.

Open the browser by dispatching the open-media-browser event:

// From Livewire — single file
$this->dispatch('open-media-browser', statePath: 'data.image', mediaType: 'image');

// Multiple files from another profile
$this->dispatch('open-media-browser',
    statePath: 'data.files',
    mediaType: 'file',
    multiple: true,
    profile: 'hero-images',
    storeReference: true,
);

// Store relative path instead of URL
$this->dispatch('open-media-browser',
    statePath: 'data.document',
    mediaType: 'file',
    storeAsUrl: false,
);
<!-- From Alpine.js -->
<button x-on:click="Livewire.dispatch('open-media-browser', {
    statePath: 'data.image',
    mediaType: 'image',
})">
    Browse Media
</button>

Listen for file selection via the media-selected event:

// Livewire
#[On('media-selected')]
public function onMediaSelected(
    string $statePath,
    string $url,
    string $alt,
    string $title,
    string $filename,
    string $extension,
    int $size,
    string $mime,
): void {
    // Use the selected media URL and metadata
}
<!-- Alpine.js -->
<div x-on:media-selected.window="handleMedia($event.detail)">

Event Reference

Event Direction Parameters
open-media-browser You → Browser statePath, mediaType? (image | media | file, derived from the profile when omitted), multiple?, profile?, storeAsUrl?, storeReference?
media-selected Browser → You statePath, url, alt, title, filename, extension, size, mime

Media Types

Value Filters
image image/* only
media video/* and audio/*
file All files (no filter)

Customizing Views

php artisan vendor:publish --tag="filament-media-browser-views"

Testing

composer test

GitHub Actions runs the Filament 3, 4, and 5 test matrix on Laravel 12 and 13. Laravel 13 needs PHP 8.3 and codepulse2020/media-upload 1.2. Laravel 10 and 11 remain accepted where Filament supports them, but they are not part of the matrix. The S3 suite runs against AWS Emulator, using a pinned and signature-verified package. With aws-emulator installed on Linux, use the same test runner locally:

bash tests/run-aws-emulator.sh

The runner uses HTTPS on loopback with the emulator's per-run credentials and CA certificate. The S3 suite exercises bucket ownership with BucketOwnerEnforced, cursor pagination, valid and expired presigned URLs, uploads, and deletion. AWS documents the emulator's bucket-policy limitations. Cloud acceptance should therefore verify the deployed policy separately. OSS virtual-hosted addressing is also outside this emulator's S3 coverage.

Changelog

Please see CHANGELOG for more information on what has changed recently.

License

The MIT License (MIT). Please see License File for more information.