Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
AJAX error when using progress bar on file field widget
An AJAX HTTP error occurred.
HTTP Result Code: 500
<code>
The cause is this:
<code>
Message RuntimeException: Controller "Drupal\file\Controller\FileWidgetAjaxController::progress()" requires that you provide a value for the "$key" argument (because there is no default value or because there is a non optional argument after this one). in Drupal\Core\Controller\ControllerResolver->doGetArguments() (line 171 of /var/www/example.ca/public_html/core/lib/Drupal/Core/Controller/ControllerResolver.php).
Proposed resolution
Indeed FileWidgetAjaxController::progress
has a $key
argument so
- Add the $upload_progress_key to the progress url
- Change the routing definition to receive the key
Remaining tasks
Refactor FileWidgetAjaxController::progress so $progress['message'] and $progress['percentage'] appears only once -- the two indexes should be be two variables. Anyways, that's a followup.
User interface changes
The AJAX progress bar begins to work.
API changes
This is not part of the API surface.
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#17 | interdiff-2587755-14-15.txt | 202 bytes | aerozeppelin |
#17 | 2587755-15.patch | 1.83 KB | aerozeppelin |
#14 | interdiff-2587755-13-14.txt | 681 bytes | aerozeppelin |
#14 | 2587755-14.patch | 2.1 KB | aerozeppelin |
#13 | interdiff-2587755-2-13.txt | 1.04 KB | aerozeppelin |
Comments
Comment #2
NickDickinsonWildeFound this error yesterday, didn't have time to fix it as it was not a blocker for my project stage. Now that I was just polishing figured I should fix it, but might as well use this issue to avoid duplicates.
The problem was that the route wasn't configured to pass the key to the controller.
Comment #3
NickDickinsonWildeThis does cause an error on file upload - doesn't actually interfere with the upload but still looks bad, so I think it should get in before the 19th.
Comment #4
cilefen CreditAttribution: cilefen commentedCan someone please post the server-side error in the issue summary?
Comment #5
NickDickinsonWildeHere's a copy of a log message:
Location http://example.ca/file/progress?_format=json
Referrer http://example.ca/file/add
Message RuntimeException: Controller "Drupal\file\Controller\FileWidgetAjaxController::progress()" requires that you provide a value for the "$key" argument (because there is no default value or because there is a non optional argument after this one). in Drupal\Core\Controller\ControllerResolver->doGetArguments() (line 171 of /var/www/example.ca/public_html/core/lib/Drupal/Core/Controller/ControllerResolver.php).
Severity Error
Comment #6
cilefen CreditAttribution: cilefen commentedComment #7
chx CreditAttribution: chx commentedComment #8
xjmThanks for the bug report!
Needs tests probably?
Comment #9
xjmComment #10
chx CreditAttribution: chx commentedNeeds tests how? Do we have AJAX tests already? Isn't this something after step2 of TNG'ing tests? dawehner is working on getting phantomjs to drupalci.
Comment #11
xjm@chx, we have been able to test the server side for AJAX requests and responses for awhile, even though we can't test the JavaScript. See WebTestBase::drupalPostAjaxForm(). Since this is a server-side error, it should indeed be testable I think.
Comment #12
chx CreditAttribution: chx commentedSo you can test path: '/file/progress/{key}' this hunk but not this $element['upload_button']['#ajax']['progress']['url'] = Url::fromRoute('file.ajax_progress', ['key' => $upload_progress_key]); . I guess that's worth a test, sure.
Comment #13
aerozeppelin CreditAttribution: aerozeppelin commentedTest for '/file/progress/{key}'.
Comment #14
aerozeppelin CreditAttribution: aerozeppelin commentedFixing typo.
Comment #15
chx CreditAttribution: chx commentedComment #16
catchWhy is locale needed in the test modules?
Comment #17
aerozeppelin CreditAttribution: aerozeppelin commentedPardon my ignorance. :D
Comment #18
swentel CreditAttribution: swentel commentedTook me a while to get this configured, but yes, this patch fixes the error. I didn't see any real 'progress' though while uploading a 700 MB file, I thought I'd see some message with percentage or so? In the end, the file as uploaded though, so maybe for a follow up ?
Moving to RTBC for feedback from committers.
Comment #19
imre.horjanThe 'Internal Server Error' is gone, however the progress meter always get a -1 in response using PECL upload progress on PHP 5.6.
I've tested upload progress on the same server with Drupal 7, and it's example from https://github.com/php/pecl-php-uploadprogress/tree/master/examples and both worked.
I think this still needs work. ( I used path #15)
Comment #20
alexpott#19 implies there is more to do here to make the progress bar work properly here.
Comment #21
swentel CreditAttribution: swentel commentedHmm yeah, both uploadprogress_get_info() apcu_fetch() return nothing .. looking into it.
We also know there's no upload progress on the testbot, so we can't write a test for it (for now).
Comment #22
imre.horjanI'm not sure how this was solved in D7 to handle multiple file upload fields in a single form, but I think we need a hidden input using the same "key" as sent back to the server to track progress:
https://harperreed.com/writing/2007/04/16/pecl-uploadprogress-example/
I have never tried APCu, so don't know how it works.
Comment #23
swentel CreditAttribution: swentel commentedThe hidden field is there:
The code is more or less the same as in D7, so it's probably going to be something trivial.
- edit - works perfect on D7 btw
Comment #24
swentel CreditAttribution: swentel commentedIt's not entirely related, but just adding it because there's various problems with file uploads - #2346893: Duplicate AJAX wrapper around a file field
Comment #25
swentel CreditAttribution: swentel commentedComment #26
swentel CreditAttribution: swentel commented#2662778: Ajax progress is rendered via JavaScript theme function; does not include progress library is a spin off to fix the theming of the progress bar.
Comment #27
swentel CreditAttribution: swentel commentedOk, I have a hint why this is failing: compare
D7 post data
with
D8 post data
The name is wrong in the D8 version. file.js tries to rename the name field temporarily (and it finds it), but it doesn't end up in the post data.
Comment #28
swentel CreditAttribution: swentel commentedI've split the issue up in #2662932: Fix file upload progress bar, I think it's better to get this one in first because it's
a) an easy and straight bug fix
b) the other one really seems to be a js problem and if we want people to help out, then i'd be easier if the fatal is already in
So therefor, RTBC.
Comment #29
catchCommitted/pushed to 8.1.x and cherry-picked to 8.0.x, thanks!
Comment #33
webservant316 CreditAttribution: webservant316 commentedI am seeing this error with Drupal 7.56 and PHP71. Problem goes away with PHP70. Is there a issue post or fix for Drupal-7.x?
Comment #34
TommyChrisPHP version 7.2.0RC5 works OK!