I am facing a similar issue to #938348: File size validation error , after attach file and try to save the bnode. only this time in the drupal 8 version of the module. In this case I don't have a second module affecting the validation of the field, simply using the core file field and adding this module on top of it to be able to use the 'File Attach' upload method.

I can see the Attach.php has the unset($validators['file_validate_size']); lines which are present in the D7 patch above but for some reason it is still trying to go through the core 'file_validate_size' function and fails due to the maximum file size error.

Has anyone else run into this issue trying to use the attach method with a file that exceeds the server's maximum file size upload limit?

Is there some field setting I might be missing that would make it bypass the core file validation?

I have done some xdebugging trying to follow the file upload process and it looks like no matter what the element validators are set to, at the end of the day the FileValidationConstraintValidator from the core file module kicks in, which then calls getUploadValidators function which forces a validation on the 'file_validate_size'.
So unless that can be somehow removed or turned off from somewhere the file attach method cannot be used to bypass the file size limit.

Comments

oldspot created an issue. See original summary.

marabak’s picture

the issue is due to
$validators = $element['#upload_validators'];
instead of :
$validators = &$element['#upload_validators'];
so the unset() is unsetting on a copy of the array.

marabak’s picture

StatusFileSize
new608 bytes

here is the patch

marabak’s picture

You are right. My patch is not working. FilItem has getUploadValidators() method called by FileValidationConstraintValidator() even if the form array is altered and the validator is unset...
I did not manage to bypass this call.

gnuget’s picture

Wouldn't be easier just update the field definition so it can allow bigger files?

rajdeep0826’s picture

StatusFileSize
new608 bytes
szato’s picture

@rajdeep0826
You uploaded the same patch file from @marabak.

@marabak
Your code
unset($validators['file_validate_size'])
removes 'file_validate_size' validation only from the filefield_source "fictive" field. So in the "value" method the file will be created/saved, but the original file field validation will fail on form submit.

Possible workaround: remove file size restriction on the field settings. If you need this validation for file upload, you have to add as a custom validation to field/form.

chrisck’s picture

I can reproduce this error using File Field Sources 8.x-1.x-dev and Drupal 9.1.12. I am using a file field for Video media entity, and the file attach method in the widget does not bypass the upload file size limit. I have also tried hook_form_alter of media_video_add_form and changed increase the byte size and/or unset ['file_validate_size'] array. Doesn't work. Due it it being a video entity it seems to be calling FileValidationConstraintValidator() in Drupal core. Wondering if anyone has found a solution thus far for FTP large files to the server and linking to a media entity, without changing the server's max upload limit site wide.

chrisck’s picture

It seems FTP and file attach method was working in D7 to bypass the file size limit. See example here: https://modulesunraveled.com/filefield-sources-and-remote-file-sources/selecting-large-files-those-uploaded-ftp

However, this is no longer true for D8, D9.