- Issue created by @asmasiddiquiCG
- ๐ฎ๐ณIndia asmasiddiquiCG
This patch adds a validator for checking file size and returns error to user if the file is blank
- Status changed to Needs review
almost 2 years ago 1:32pm 2 March 2023 The last submitted patch, 4: 3345450-4-restrict-zero-byte-file-upload.patch, failed testing. View results โ
- Status changed to Needs work
almost 2 years ago 10:28am 3 March 2023 - ๐ฎ๐ณIndia asmasiddiquiCG
Resolved test errors and resubmitting the patch
- Status changed to Needs review
almost 2 years ago 2:11am 8 March 2023 - ๐จ๐ดColombia yovanny.gomez.oyola
Hi @asmasiddiquiCG thanks for the patch.
I have validated it and it works fine on:
Drupal core version: 10.0.4
PHP version: 8.1.14
Mysql version: 8.0.31The result is as expected. But I see that the test keeps failing. Can you validate it?
- Status changed to Needs work
almost 2 years ago 7:51pm 10 March 2023 - ๐บ๐ธUnited States smustgrave
Did not test.
But this will require a test case showing the bug.
This is reported as having been fixed in #2377747: Incorrect node create validation error when an invalid image is attached to a field โ . Or, is this different?
- ๐จ๐ดColombia yovanny.gomez.oyola
Hi @cilefen,
In the ticket you mention, only the error message is being changed when the !$image->isValid() function fails. But in this case what we want to validate is that the user cannot upload empty files to the CMS. I think they are 2 different things.
- ๐ฎ๐ณIndia asmasiddiquiCG
I am unable to solve the error thrown in patch test, can someone guide?
Error below
1) Drupal\Tests\jsonapi\Functional\MediaTest::testPostIndividual
The 'errors' member was not as expected.
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
0 => Array (
0 => '422'
1 => 'Unprocessable Content'
- 2 => 'name: Name: this field cannot hold more than 1 values.'
+ 2 => 'field_media_file.0: The file you uploaded is empty! Please check whether you want to upload the selected file'
3 => Array (
- 0 => '/data/attributes/name'
+ 0 => '/data/attributes/field_media_file/0'
)
)
+ 1 => Array (...)
) - ๐ฆ๐บAustralia kim.pepper ๐โโ๏ธ๐ฆ๐บSydney, Australia
Since UploadedFile validator was added in ๐ Create an UploadedFile validator and deprecate error checking methods on UploadedFileInterface RTBC you need to create a plugin and add the additional validator to your upload form settings.
See
core/modules/file/src/Plugin/Validation/Constraint/FileSizeLimitConstraint.php
as an example of the validating the maximum filesize. - First commit to issue fork.
- Merge request !5555Added a contraint to check for empty file upload. โ (Open) created by ameymudras
- Status changed to Needs review
about 1 year ago 9:28am 27 November 2023 - ๐ฎ๐ณIndia ameymudras
@kim.pepper thanks for the suggestion. Ive added a validation constraint to check for an empty file. Appreciate if you could review and suggest changes / issues if any.
It still Needs tests though
- Status changed to Needs work
about 1 year ago 3:42pm 27 November 2023 - ๐บ๐ธUnited States smustgrave
Was previously tagged for tests which are still needed too.
- First commit to issue fork.
- Status changed to Needs review
about 1 year ago 4:26am 30 November 2023 - ๐ป๐ณVietnam phthlaap
It seems to conflict with a test in the JSONAPI module. They expected the zero-byte file to upload successfully.
\Drupal\Tests\jsonapi\Functional\FileUploadTest::testFileUploadZeroByteFile
- Status changed to Needs work
about 1 year ago 3:14pm 30 November 2023 - ๐บ๐ธUnited States smustgrave
Seems to have test failures.
Have not reviewed.
- ๐ป๐ณVietnam phthlaap
As I mentioned in comment #23, the Json API module has a test to ensure that a file with zero bytes can be uploaded successfully. That test conflicts with this feature request, and I am unsure about what steps to take next.
\Drupal\Tests\jsonapi\Functional\FileUploadTest::testFileUploadZeroByteFile