With Drupal's page cache enabled and more than one file upload field on a form, uploading to the first via the "Upload" button and then trying the same for the second produces an erroneous "the uploaded file likely exceeded the maximum file size" error message.
For Drupal 7, #2339109: Multiple file uploads don't work with Drupal cache enabled contains a lot of discussion of the problem and steps to reproduce it using Webform.
I assume Drupal 8 is affected too since the code is similar, but I haven't tested.
One possible way to fix this - just remove the code that throws the error. The error message suggests that it's there to catch cases where a file is bigger than the upload limit supported by the server, although it's not obvious how the code is related to that - clearly there's at least one case (this one) where it works incorrectly. And even so, the form API validation should already be preventing files that are too large from ever being uploaded in the first place.
| Comment | File | Size | Author |
|---|---|---|---|
| #41 | file-ajax-upload-239117-D7-41.patch | 1.55 KB | sinduri |
| #37 | file-ajax-upload-2392117-37-D7-do-not-test.patch | 1.13 KB | petyosv |
| #17 | 2392117-17.patch | 1.5 KB | stefan.r |
| #7 | forms_with_multiple-2392117-7.patch | 1.24 KB | siva_epari |
| #1 | file-ajax-upload-2392117-1-D8.patch | 1.23 KB | David_Rothstein |
Comments
Comment #1
David_Rothstein commentedHere are patches for Drupal 7 and Drupal 8.
Manual testing suggests the Drupal 7 patch fixes the bug, so hopefully it really is this simple?
Comment #2
David_Rothstein commentedBy the way, these are just minimal patches. (At least for the Drupal 8 version, we might consider removing the no-longer-needed form build ID from the URL as well.)
Comment #3
andyanderso commentedThese patches worked for me - In this case, as David_Rothstein, suggests do we even need the error message? It seems redundant...
Comment #6
mgiffordThis still works fine in D7. The D8 version needs to be re-rolled. Would be good to get this fixed as we're having to apply this to live sites in D7 right now.
Comment #7
siva_epari commentedPatch rerolled.
Comment #11
stefan.r commentedUpgrading priority as this prevents multiple files from being uploaded
Comment #13
stefan.r commentedComment #14
stefan.r commentedIn #1489692: Incorrect handling of file upload limit exceeded - file widget disappears it suggests that we do need the check. Maybe we should do a similar check there as in file_save_upload() and instead of deleting the validation code, only run it when any of the files in $_FILES are larger than file_upload_max_size()?
Comment #15
stefan.r commentedComment #16
mgiffordPatch no longer applies.
Comment #17
stefan.r commentedre-roll of #7
Comment #19
rudiedirkx commentedThe patch 'works' because you're removing the check. It probably existed for a reason. If the check is bad, we should fix what it does. If the check highlights a file upload problem, we should fix that. Obviously.
The problem I have seems a form build id mismatch, sometimes, on a Webform with several file uploads. Most times, there's no problem. Sometimes there is.
IDs in file upload ajax URLs:
For example:
The form's ID:
For example:
(All 5 are the same, so no problem.)
I still don't know why it does this, but it might help someone.
Comment #20
rudiedirkx commentedComment #21
David_Rothstein commentedYeah, this code does run when you upload a file that's bigger than the server filesize limit. However, given how broken it is (not just this issue, but #1489692: Incorrect handling of file upload limit exceeded - file widget disappears is even worse) removing it and letting the upload fail silently honestly might still be a temporary improvement. Of course, fixing it would be better :)
I don't understand the title change; how do you reproduce this without multiple file upload fields?
Comment #22
rudiedirkx commentedThe multiple part was important, sorry, but the file upload fields was misleading: it happens for file Elements, not Fields.
The upload limit fix might be as simple as removing
$form_build_id !== $request_form_build_idfrom the check... The check should trigger because there's NO data in the request, not because the id is different. The id being different must have another reason. It'd still be good to find and fix that reason of course.I've fixed it on my website by disabling page cache for webforms, which Field seems to do too (I couldn't reproduce the error on a node form, but easily on a webform).
Comment #23
elijah lynnComment #24
elijah lynnComment #25
elijah lynnComment #26
elijah lynnWe are experiencing this issue after migrating to a different hosting environment. I am just putting this here to trigger ideas. I don't know what changed between environments. If I do figure it out I will post back.
Comment #27
elijah lynnWe applied the patch in #1 but not to file_ajax_upload but media_ajax_upload and while it does get rid of that error I am still pursuing a deeper fix.
Comment #28
gábor hojtsyComment #29
gábor hojtsyNow using the proper media tag. Sorry.
Comment #34
sjerdoExperiencing this issue in D7.
When the buildId of the form is updated, the ajax path for uploading a file is not updatet to the correct buildid.
Eg. files are uploaded to /file/ajax/uploadfield/form-OLDBUILD id instead of /file/ajax/uploadfield/form-NEWBUILDID
This is fixed by updating the JS settings of the form when the buildId is updatet. This will include the correct AJAX upload path.
Comment #35
pyg77 commentedHi @sjerdo : I experienced the same issue.
Where (on which file) do I need to apply your patch ?
Comment #36
sjerdoMoving this issue back to D7 since this presumably has been resolved for D8 in issue #2500527: Rewrite \Drupal\file\Controller\FileWidgetAjaxController::upload() to not rely on form cache, since D8 no longer contains the form_build_id in the URL for file uploads.
D7 still contains this bug when the form contains one or more AJAX elements of which one is a file upload field.
Comment #37
petyosv commentedUpdate for D7.59
Comment #38
paul.hendrick commented#37 has resolved our issue; thanks!
In our case, we had just started using Authcache for anonymous users, not Drupal cache. However the behavior we observed was the same as described here (first file upload works fine but changes the form build id, subsequent file upload requests hit the old build id and throw an error).
So, we applied the patch in #37 and found it works for us.
Comment #39
klonosI'm trying to reproduce this issue on a mostly vanilla Drupal 7.81 site (only admin_menu installed, for ease of navigation). The issue summary says:
Based on that, I've done the following:
What am I missing in order to reproduce this?
Comment #40
scottAtRoot802 commentedklonos, I've noticed the issue can be illusive to reproduce. The key seems to be in the browser cookies. I've been able to reliably reproduce the issue by following the a couple steps.
First, you need to be logged out to test the issue. Then, clear your browser cookies. As an anonymous user, fill out the form. Upload the first file should work with no issues. The second, third, etc. should trigger the error.
Assuming the error triggered for you, try reloading the form and fill out the form again. This time the multiple file uploads should all work, misleading you into thinking the issue resolved itself which is not true. The key difference is in two session cookies that are created after the first file upload, plus a subsequent page reload. As long as those cookies are present, the multiple file uploads continues to work. Clear those cookies and the issue returns.
I'm not sure if this is a side effect of the form_build_id issue, or a root cause. I'm still investigating.
Comment #41
sinduriReroll for #37. Update for 7.93
Comment #42
poker10 commentedAside from the two failures which are caused by the new tests, this is unlikely to be committed in this form (see #19, #22, #39, #40).
Removing the check is "nice", but it does not solve the problem (or problems), it will only hide the problem. Without this check, the form with an empty
$_POSTdata will fail silently and I think it is the same than the current state.I saw this error personally when the whole
$_POSTdata were empty and this triggered the error, not the mismatch of theform_build_ids. So it would be nice to find the root cause here, or if there are multiple root causes combined, then rescope this issue summary.Also there are some related comments for this in #2749245: Back port: Incorrect handling of file upload limit exceeded - file widget disappears, in comments #8 and #9.
Comment #43
poker10 commentedMaybe we can try the approach from #2787243: Multiple AJAX File uploads in one form breaks for anonymous user.