Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

A Filament file upload field fails or shows no file on S3

ErrorThe upload bar fails or the file is rejected for larger files

Short answer

A Filament upload goes first to Livewire's temporary storage and only then to your S3 disk. Large files hit Livewire's 12MB default or PHP's upload_max_filesize. Saved files can still not open because the disk name makes them private, or the browser is blocked by missing CORS headers on the bucket.

  • Applies to Filament 4, Livewire 3, Laravel 12, PHP 8.3
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Try a tiny file first. If it works, the cause is a size limit; if it saves but will not open, look at visibility and CORS.

    php artisan config:show livewire
    php -r "echo ini_get('upload_max_filesize'), PHP_EOL;"
  2. 2Match what you see, then jump to its fix

    1. 1Files above about 12MB fail while small ones upload.Larger files exceed Livewire's default limitFix
    2. 2Even after raising Livewire's rule, the larger upload still fails.PHP's own upload limit is smallerFix
    3. 3The object exists in the bucket but the saved file cannot be viewed.The file is private, so its link does not openFix
    4. 4The browser console shows a cross-origin block when the preview loads.The bucket sends no CORS headersFix

What does the error look like?

  • The upload bar fails or the file is rejected for larger files
  • The file is saved to S3 but its preview or link does not open
  • Previews fail in the browser console with a cross-origin error

Cause 1 of 4

Larger files exceed Livewire's default limit

1Check

Livewire validates every temporary upload with a default of max 12MB, and the limit is set in the rules key of temporary_file_upload.

php artisan livewire:publish --config

2Fix

Raise the limit in config/livewire.php; the value is in kilobytes.

'temporary_file_upload' => [
    'rules' => ['file', 'max:102400'], // 100MB
],

3Verify

Upload a file between 12MB and the new limit.

php artisan config:show livewire

Confirmed by livewire.laravel.com

Did this fix it?

Cause 2 of 4

PHP's own upload limit is smaller

1Check

Filament's docs point to php.ini upload_max_filesize as the other limit for failing large uploads.

php -i | grep -E "upload_max_filesize|post_max_size"

2Fix

Raise it in the php.ini used by PHP-FPM, then restart PHP-FPM.

; php.ini
upload_max_filesize = 120M

3Verify

Read the value back from the web SAPI, not only the CLI.

sudo systemctl restart php8.3-fpm

Confirmed by filamentphp.com

Did this fix it?

Cause 3 of 4

The file is private, so its link does not open

1Check

Filament uploads with private visibility unless the disk is named public, and it decides this by the disk's name, not its filesystem config.

grep -rn "FileUpload::make" app/

2Fix

Set visibility on the field explicitly for your S3 disk, or use temporary URLs if the files should stay private.

FileUpload::make('attachment')
    ->disk('s3')
    ->directory('form-attachments')
    ->visibility('public')

3Verify

Create a new upload and open its link.

grep -rn "visibility" app/

Confirmed by filamentphp.com

Did this fix it?

Cause 4 of 4

The bucket sends no CORS headers

1Check

The Filament docs say that if files are hosted on a separate domain such as S3, CORS headers must be set up.

aws s3api put-bucket-cors --help

2Fix

Add a CORS rule to the bucket that allows your app's origin.

aws s3api put-bucket-cors --bucket my-bucket --cors-configuration file://cors.json

3Verify

Reload the form and check the browser console no longer shows the cross-origin error.

cat cors.json

Confirmed by filamentphp.com

Did this fix it?

How do I stop it coming back?

  • Decide the upload limit once and set Livewire's rules, upload_max_filesize and post_max_size together.
  • Set visibility on every FileUpload that uses a custom disk name.
  • Keep the bucket CORS rule in version control.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

composer require maatwebsite/excel fails to install

Composer says the package needs an older PHP than the one installed

Composer refuses maatwebsite/excel when the PHP version or a PHP extension does not match what the package and PhpSpreadsheet need.

3 causes, each with a fix

Back end

composer require laravel/horizon fails: ext-pcntl is missing

laravel/horizon v1.1.0 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system

Horizon needs the pcntl extension, and Composer refuses to install it where PHP lacks that extension.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.