0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Laravel + livewireで大きなサイズのファイルをアップロードすると422エラーになる

Last updated at Posted at 2025-09-29

12MBを超えるファイルをアップロードすると、livewireのupload-fileが422 Unprocessable Contentでエラーになった。

原因

livewireの一時ファイルの処理ルールのデフォルトが上限12MBとなっているため。
PHPのupload_max_filesizeなどに問題は無かったせいで、PHPのファイルアップロード周りに落とし穴でもあるかと疑ってしまった。ごめんPHP。

config/livewire.php
()
    'temporary_file_upload' => [
        ()
        'rules' => null,       // Example: ['file', 'mimes:png,jpg']  | Default: ['required', 'file', 'max:12288'] (12MB)

参考)https://stackoverflow.com/questions/65580792/livewire-image-upload-422-unprocessed-entity-error

対処

参考元ではコードで書き換えているが、素直に(単純に)設定ファイルで設定するようにした。

$ php artisan vendor:publish
  ... いろいろ表示されるが、livewire:configを選択すると
  config/livewire.php が生成される。

生成されたconfig/livewire.phpの該当箇所を変更。

config/livewire.php
()
    'temporary_file_upload' => [
        ()
-        'rules' => null,       // Example: ['file', 'mimes:png,jpg']  | Default: ['required', 'file', 'max:12288'] (12MB)
+        'rules' => ['required', 'file', 'max:30720'],
        
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?