Livewire 图片上传 422 未处理实体错误

问题描述 投票:0回答:1

我需要帮助, 我尝试使用 Livewire 上传图像,但当图像大小超过 2MB 时遇到 422(无法处理的实体)错误。

我正在使用 Wamp 服务器,我在 php.ini 中增加了内存限制和上传大小,但错误仍然存在

javascript php laravel image intervention
1个回答
0
投票

我经历过类似的事情,并找到了解决方案。也许它可以帮助别人。

实际上,Livewire 上传默认对临时文件有最大验证,我们可以在 config/livewire.php 中更改它:

...
    'temporary_file_upload' => [
        'disk' => null,        // Example: 'local', 's3'              Default: 'default'
        'rules' => null,       // Example: ['file', 'mimes:png,jpg']  Default: ['required', 'file', 'max:12288'] (12MB)
        'directory' => null,   // Example: 'tmp'                      Default  'livewire-tmp'
        'middleware' => null,  // Example: 'throttle:5,1'             Default: 'throttle:60,1'
        'preview_mimes' => [   // Supported file types for temporary pre-signed file URLs.
            'png', 'gif', 'bmp', 'svg', 'wav', 'mp4',
            'mov', 'avi', 'wmv', 'mp3', 'm4a',
            'jpg', 'jpeg', 'mpga', 'webp', 'wma',
        ],
        'max_upload_time' => 5, // Max duration (in minutes) before an upload gets invalidated.
    ],
...

在规则中,我们可以对其进行设置:

'rules' => ['required', 'file', 'max:52288'], 
© www.soinside.com 2019 - 2024. All rights reserved.