Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try to import a file larger than 1MB, a validation error will occur. #12842

Closed
bzy107 opened this issue May 17, 2024 · 7 comments
Closed

try to import a file larger than 1MB, a validation error will occur. #12842

bzy107 opened this issue May 17, 2024 · 7 comments
Labels

Comments

@bzy107
Copy link
Contributor

bzy107 commented May 17, 2024

Package

filament/filament

Package Version

v3.2.80

Laravel Version

v11.7.0

Livewire Version

v3.4.12

PHP Version

PHP8.3.7

Problem description

If you try to import a file larger than 1MB, a validation error occurs and the import fails. This is likely a validation error on the front end from Livewire or Filepond, but the exact cause is unclear.
This occurs when a file is selected or dragged and dropped.

スクリーンショット 2024-05-18 0 12 17

The importer has a feature to specify the maximum number of rows with maxRows(), but there is no feature to specify the file size. It would be very useful to have control similar to a maxSize() feature.

Please consider this.

Expected behavior

Should be imported

Steps to reproduce

On the /admin/patients screen, perform the import using ./storage/export-1-patients_over1M.csv.

Reproduction video:

2024-05-17.23.47.40.mov

Reproduction repository

https://github.com/bzy107/filament-select-bug

Relevant log output

No response

@bzy107 bzy107 added bug Something isn't working medium priority unconfirmed labels May 17, 2024
@petrisorcraciun
Copy link

petrisorcraciun commented May 21, 2024

check config/livewire.php -> temporary_file_upload -> 'max:...',

@bzy107
Copy link
Contributor Author

bzy107 commented May 21, 2024

check config/livewire.php -> temporary_file_upload -> 'max:...',

I tried it, but it didn't work.
The same error occurs when the size exceeds 1MB. So, it seems to be caught by the validation before it even reaches livewire.php, but I don't understand the lifecycle well enough to pinpoint the exact issue.

when 'rules' => ['max:1024']:
スクリーンショット 2024-05-21 19 48 52

when 'rules' => ['max:1023']:
スクリーンショット 2024-05-21 19 48 19

@aSeriousDeveloper
Copy link
Contributor

File Upload size validation is handled by the minSize and maxSize functions on the form component: https://filamentphp.com/docs/3.x/forms/fields/file-upload#file-size-validation

This is because FilePond, the JS package used for file uploads, has its own validation for file size that filament hooks into.

However, with the FileUpload component being baked into the Import Action, there's no easy way to modify these values yourself.

The max filesize should automatically be set to null if it isn't provided automatically, which would make me assume that any size would work. Can you check your phpinfo(); for your upload_max_filesize ?

Where values are set within the blade component

maxSize: @js(($size = $getMaxSize()) ? "{$size}KB" : null),
minSize: @js(($size = $getMinSize()) ? "{$size}KB" : null),

Where the FileUpload component is made in the ImportAction

FileUpload::make('file')
->label(__('filament-actions::import.modal.form.file.label'))
->placeholder(__('filament-actions::import.modal.form.file.placeholder'))
->acceptedFileTypes(['text/csv', 'text/x-csv', 'application/csv', 'application/x-csv', 'text/comma-separated-values', 'text/x-comma-separated-values', 'text/plain', 'application/vnd.ms-excel'])

@bzy107
Copy link
Contributor Author

bzy107 commented May 21, 2024

Thank you for your reply. I have already checked the same points.

Since $getMinSize in FilePond is not set, it should be null.
upload_max_filesize is also set to 2MB, so that’s not the issue.
Therefore, I’m stuck.

@bzy107
Copy link
Contributor Author

bzy107 commented May 21, 2024

So, does this mean that currently in the importer, we can't set minSize() and maxSize(), so we should add methods for them?
I need to investigate a bit more.

@bzy107
Copy link
Contributor Author

bzy107 commented May 21, 2024

Progress Update:

I modified the CanImportRecords.php file to add maxSize(), but it didn't work. Further investigation is needed.

maxSize set 100MB:
スクリーンショット 2024-05-22 1 14 47
スクリーンショット 2024-05-22 1 16 27

@bzy107
Copy link
Contributor Author

bzy107 commented May 21, 2024

I found the cause.
It was not on the Filament side but on the Nginx side, where I overlooked a 413 Request Entity Too Large error.
スクリーンショット 2024-05-22 1 37 37

I resolved it by adding the client_max_body_size setting.

server {
    client_max_body_size 10M;
    ....

I hope this helps anyone who encounters the same issue.

@bzy107 bzy107 closed this as completed May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

No branches or pull requests

3 participants