Currently the system uses either: PECL uploadprogress http://pecl.php.net/package/uploadprogress or APC rfc1867 to show file upload progress (neither of which work with PHP 7 and nginx).

There was a discussion here https://www.drupal.org/node/1561866 about using the built in php session upload progress (PHP 5.4+) however Drupal's implementation of PHP session seems to interfere with this in a lot of cases.

https://www.drupal.org/u/droplet suggested that as D8 uses the jQuery.form plugin, it's proposed that we remove the reliance on 3rd party PHP libraries in the built in session upload progress and go with a the jQuery.form client side solution.

I have attached a patch that implements this and removes the old solutions.

It definitely needs review and some additional work (I would like this to work with remote file systems and CORS upload eventually).

Tested with Apache2 and nginx in Chrome (latest version).
I suspect there may be issues with Internet Explorer 9 compatibility. Does anyone know if there is a fallback built into jQuery.form to handle this?

CommentFileSizeAuthor
#73 upload_progress-2833968-73.patch7.78 KBchucksimply
#71 2833968-71.patch9.34 KBpradhumanjain2311
#68 upload_progress-2833968-68.patch7.79 KBkyriazo
#67 upload_progress-2833968-67.patch7.75 KBbrunodbo
#62 2833968-62.patch9.52 KBsteveoriol
#61 2833968-61.patch9.56 KBNitin shrivastava
#60 2833968-60.patch9.52 KBsteveoriol
#46 interdiff_38-46.txt453 bytesNeslee Canil Pinto
#46 2833968-46.patch9.33 KBNeslee Canil Pinto
#41 upload_progress-2833968-41.patch9.33 KBbrunodbo
#38 upload_progress-2833968-38.patch9.32 KBTim Bozeman
#36 upload_progress-2833968-36.patch8.83 KBsteveoriol
#34 upload_progress-2833968-34.patch7.67 KBTim Bozeman
#31 Upload_progress-2833968-30.patch10.88 KBsteveoriol
#29 Upload_progress-2833968-29.patch12.13 KBsteveoriol
#27 2833968-26.patch9.77 KBjerrylow
#26 interdiff.txt1.03 KBjerrylow
#26 2833968-25.patch9.67 KBjerrylow
#26 2833968-ajax-error.png55.68 KBjerrylow
#24 core-jquery.form_upload_progress-2833968-24.patch9.64 KBbrunodbo
#23 core-jquery.form_upload_progress-2833968-23.patch11.47 KBbrunodbo
#19 core-jquery.form_upload_progress-2833968-19.patch11.29 KBbrunodbo
#9 core-jquery.form_upload_progress-2833968-9-8.3.x.patch9.86 KBrjjakes
#17 core-jquery.form_upload_progress-2833968-16.patch11.3 KBbrunodbo
#15 core-jquery.form_upload_progress-2833968-15-8.3.x.patch9.37 KBsteveoriol
#2 core-jquery.form_upload_progress-2833968-2-8.3.x.patch9.7 KBrjjakes

Issue fork drupal-2833968

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rjjakes created an issue. See original summary.

rjjakes’s picture

Status: Needs review » Needs work

The last submitted patch, 2: core-jquery.form_upload_progress-2833968-2-8.3.x.patch, failed testing.

andypost’s picture

Looks great, only fix tests left and approval about backward compatibility

+++ b/core/modules/file/file.install
@@ -63,60 +63,11 @@ function file_schema() {
       'title' => t('Upload progress'),
...
+      'value' => t('jQuery.form uploadProgress'),
+      'description' => t('Drupal 8 uses client side jQuery.form uploadProgress. No extensions are required.'),

not clear is this this needed?
maybe some setting still can block that?

rjjakes’s picture

Hi @andypost, I'll do the test fix later today when I get chance.

I wasn't sure if we should keep the entry on the status page either. Perhaps it would be useful as an indicator that things have change (then we can plan to remove it completely for a much later release?)

droplet’s picture

Thanks @rjjakes !

We can keep current PHP code as BC layer. (Until we have a final decision: #2390621: [policy, no patch] Update Drupal's browser support policy)

+++ b/core/modules/file/src/Controller/FileWidgetAjaxController.php
@@ -24,20 +24,9 @@ public function progress($key) {
+    if (isset($_GET['loaded']) && isset($_GET['total']))  {
+      $progress['message'] = t('Uploading... (@current of @total)', array('@current' => format_size($_GET['loaded']), '@total' => format_size($_GET['total'])));
+      $progress['percentage'] = round(100 * $_GET['loaded'] / $_GET['total']);
     }

It's 100% client-side. We can drop it I think.

I wasn't sure if we should keep the entry on the status page either. Perhaps it would be useful as an indicator that things have change (then we can plan to remove it completely for a much later release?)

Might be we only tell it doesn't work in older IE & browser do not support ProgressEvent..

droplet’s picture

rjjakes’s picture

@droplet - I made the call back to the fileprogress endpoint (core/modules/file/src/Controller/FileWidgetAjaxController.php in this case) with additional data to keep as much of the existing code in place as possible. Are you saying I should drop this in favour of a purely client side solution? If so, this is significantly more refactoring and has the potential to break the batch progress too.
I think we should keep it as is (calling back via AJAX to core/modules/file/src/Controller/FileWidgetAjaxController.php) to maintain consistency.

rjjakes’s picture

rjjakes’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 9: core-jquery.form_upload_progress-2833968-9-8.3.x.patch, failed testing.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

steveoriol’s picture

Hello rjjakes,

Thank you, after patched by hand 3 files on D8.3.7 , It is working good :-)

xxx@xxxxx:/home/sites/drupal8⟫ patch -p1 < sites/PATCHS/core-jquery.form_upload_progress-2833968-9-8.3.x.patch
patching file core/misc/ajax.js
patching file core/misc/progress.js
patching file core/modules/file/file.install
Hunk #1 FAILED at 63.
1 out of 1 hunk FAILED -- saving rejects to file core/modules/file/file.install.rej
patching file core/modules/file/file.module
Hunk #1 FAILED at 913.
1 out of 1 hunk FAILED -- saving rejects to file core/modules/file/file.module.rej
patching file core/modules/file/src/Controller/FileWidgetAjaxController.php
Hunk #1 FAILED at 24.
1 out of 1 hunk FAILED -- saving rejects to file core/modules/file/src/Controller/FileWidgetAjaxController.php.rej
patching file core/modules/file/src/Element/ManagedFile.php
steveoriol’s picture

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

brunodbo’s picture

Status: Needs work » Needs review
FileSize
11.3 KB

Rerolled the patch in #15 for 8.6.x; it also applies to 8.5.3.

Status: Needs review » Needs work

The last submitted patch, 17: core-jquery.form_upload_progress-2833968-16.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

brunodbo’s picture

Status: Needs work » Needs review
FileSize
11.29 KB

Fixing coding standards.

Status: Needs review » Needs work

The last submitted patch, 19: core-jquery.form_upload_progress-2833968-19.patch, failed testing. View results

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

quicksketch’s picture

We've ported this implementation over to Backdrop in https://github.com/backdrop/backdrop-issues/issues/3211.

+  Drupal.Ajax.prototype.uploadProgress = function (event, position, total, percentComplete) {
+    this.progress.object.setProgressdata({
+      loaded: position,
+      total: total
+    });
+  };

I don't think there's any need for the new `setProgressdata()` method or to call it here. The progress object already has a `setProgress()` method that could just move the progress bar.

The Backdrop implementation also takes @_nod's suggestion and just switches the implementation to be entirely client-side. If you'd like to continue supporting old browsers, Backdrop lets uploadprogress or APC (if available) take precedence, but honestly the client-side only implementation is better all around. Browser support is very good at this point: https://caniuse.com/#feat=xhr2

brunodbo’s picture

Status: Needs work » Needs review
FileSize
11.47 KB

To keep this going, here's a reroll of the patch in #19 against 8.7.x. Also applies against 8.6.x.

brunodbo’s picture

As suggested in #22, this patch uses setProgress() to move the progress bar instead of a newly added setProgressdata() method.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jerrylow’s picture

Oops uploaded the wrong patch.

13087285 Ajax error

steveoriol’s picture

Hello,
the patch applies well, the progress bar is also displayed, but it remains motionless at the beginning without growing until the end of the file upload (I forgot to empty the cache) ...
If I go back to the network tab of the dev tools, I have progress requests that go well,

https://xxxxxxxxxx.com/file/progress/61023309?_format=json
https://xxxxxxxxxx.com/file/progress/61023309?_format=json
[...]

but the answer is always:
{"message": "Starting upload ...", "percentage": - 1}
it is as if the GET 'loaded' and 'total' variables were not sent or received.
But why always use the return json if the code uses the function "setProgress (percentage, message, label)" by now ?

I put a:
console.log ('percentage:' + percentage + ', message:' + message + ', label:' + label);
in the "setProgress" function and I have the following:

percentage:5 , message:undefined , label:undefined
percentage:-1 , message:Starting upload... , label:undefined
percentage:7 , message:undefined , label:undefined
percentage:9 , message:undefined , label:undefined
percentage:11 , message:undefined , label:undefined
percentage:13 , message:undefined , label:undefined
percentage:-1 , message:Starting upload... , label:undefined
percentage:15 , message:undefined , label:undefined
percentage:17 , message:undefined , label:undefined
percentage:19 , message:undefined , label:undefined
percentage:21 , message:undefined , label:undefined
percentage:-1 , message:Starting upload... , label:undefined
percentage:23 , message:undefined , label:undefined
percentage:26 , message:undefined , label:undefined
[...]
percentage:100 , message:undefined , label:undefined
percentage:-1 , message:Starting upload... , label:undefined

why, the ligne "percentage:-1 , message:Starting upload... , label:undefined" ?
why message never indicate "Uploading... (@current of @total)" ?

steveoriol’s picture

Hello again,
I modified the last patch to work at home on D8.7.2 (to display the message above the progress bar), it's probably not very good coding, but it works, do not hesitate to rot and make the changes you need ;-)

Status: Needs review » Needs work

The last submitted patch, 29: Upload_progress-2833968-29.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

steveoriol’s picture

I removed too many things in my last patch and the progress bar for something other than images no longer function (update translation, etc.)
Here is the new one.

Alex Pshegodskyi’s picture

Thank you for your patch, it work great for upload using regular drupal forms, but not working when uploading file using file manager, any idea how to make it work in file manager too?

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Tim Bozeman’s picture

Status: Needs work » Needs review
Issue tags: -JavaScript +JavaScript
FileSize
7.67 KB

Rerolled for 8.8.

steveoriol’s picture

Hello,
The patch applies well, but on my side the progress bar remains glued to the left until the document has finished downloading ...

steveoriol’s picture

This patch works for me, by added "ajax.uploadProgress" inside the 2 js files...

Status: Needs review » Needs work

The last submitted patch, 36: upload_progress-2833968-36.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Tim Bozeman’s picture

Status: Needs work » Needs review
FileSize
9.32 KB

Thanks Steve!
Whoops. @douggreen pointed out that the re-roll left a bit of cruft.

Status: Needs review » Needs work

The last submitted patch, 38: upload_progress-2833968-38.patch, failed testing. View results

steveoriol’s picture

Review OK for me with patch 38 :-)

brunodbo’s picture

I noticed a PHP notice on the Status report, this patch should fix that.

brunodbo’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 41: upload_progress-2833968-41.patch, failed testing. View results

andypost’s picture

Sadly no interdiffs in last patches...

+++ b/core/misc/ajax.es6.js
@@ -903,6 +906,27 @@
+        const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB']
...
+      $message = Drupal.t('Uploading... (@current of @total)', {'@current': bytesToSize(position), '@total': bytesToSize(total)});

Are you sure that TB is enough? The core's `format_size()` function provides 4 more and makes them translatable

joelpittet’s picture

Here's the interdiff between 38-41, it's small enough to not need a file.

diff --git a/core/modules/file/file.install b/core/modules/file/file.install
index aedf295686..4e8aa28ec4 100644
--- a/core/modules/file/file.install
+++ b/core/modules/file/file.install
@@ -67,6 +67,7 @@ function file_schema() {
 function file_requirements($phase) {
   return [
     'file_progress' => [
+      'title' => t('Upload progress'),
       'value' => t('jQuery.form uploadProgress'),
       'description' => t('Drupal 8 uses client side jQuery.form uploadProgress. No extensions are requried.'),
     ],
Neslee Canil Pinto’s picture

Status: Needs review » Needs work

The last submitted patch, 46: 2833968-46.patch, failed testing. View results

Neslee Canil Pinto’s picture

Status: Needs work » Needs review
jungle’s picture

Status: Needs review » Needs work

Tests did not pass

joelpittet’s picture

Status: Needs work » Needs review

I'm wondering since we seem to be moving away from jQuery UI and maybe jQuery too, that we could use something like this:
https://htmldom.dev/upload-files-with-ajax/

Feel free to punt me to a new issue if that is diverging too far from this issues scope.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

steveoriol’s picture

Patch #46 still works on D9.2.7 :-)

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

chucksimply’s picture

Just want to confirm... patch #46 works on 9.4.5.

I tried for months trying to get PECL uploadprogress package working on my server and drupal site. Never could. This patch was such a simple solution.

Would be great to get a new patch file that passes tests. And move forward on getting it into core.

andypost’s picture

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

steveoriol’s picture

Nitin shrivastava’s picture

steveoriol’s picture

New try to pass test...

There are always some mistakes :-(
But still, the patch works well for D9.5.0.
And for D10, the patch generated from the "merge request !3190" also works.
D10 patch : https://git.drupalcode.org/project/drupal/-/merge_requests/3190.patch

smustgrave’s picture

This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

MR had a CI failure and still needs tests.
Hiding the files to avoid confusion.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

brunodbo’s picture

This is a reroll of #62 for 11.x, which also applies to 10.1.x. I'm getting an error when trying to create an interdiff that I'm unable to figure out at the moment (interdiff fails to process the patch files for some reason). This patch a straight reroll of the patch in #62. The only change is that I omitted the Drupal version number in the changes to file_requirements(), and in the comment for file_progress_implementation().

Do we need the file_requirements() at all? There is no system information to display anymore on the status report, so we could remove that message.

Leaving as needs work for tests.

kyriazo’s picture

This is a re-roll of patch #67 works but gives an error since SystemManager's listRequirements method expects a title on the requirement and gives an error on 10.1.x.

KlemenDEV’s picture

steveoriol’s picture

Patch #68 works for me on D10.1.6 😀

pradhumanjain2311’s picture

Fix Patch not apply for 11.x

smustgrave’s picture

Status: Needs review » Needs work

Please include interdiffs with patches, also encouraged to start using MRs instead.

Seems this was tagged for tests which reroll didn't have

chucksimply’s picture

#68 doesn't apply to 10.2, and #71 applies to 10.2 but doesn't show progress correctly (bar just goes straight to 100%).

Here is a new working patch based on #68 for 10.2.