[Catalyst] C::P::UploadProgress Patch

Adam Herzog adam at herzogdesigns.com
Fri Jun 1 16:09:21 GMT 2007


Hi, all.

I'm using Catalyst::Plugin::UploadProgress on a project of mine, and  
it works great. At least, until I tried to deploy the application.  
The plugin and accompanying javascript only works correctly if the  
app is deployed at the root (ie, it always checks /progress).

I've attached a patch (svn diff) which allows the plugin to be used  
when an app is deployed at a non-root location, like http:// 
domain.tld/myapp/.

I would have liked to add some tests for my changes, but, to be  
honest, I don't really know how to test deployment issues like this.  
If somebody has some pointers, I'd be happy to add the appropriate  
tests.

If there aren't any problems with it, can somebody apply the patch  
and push a new release, please?

Thanks,
-A


Index: lib/Catalyst/Plugin/UploadProgress.pm
===================================================================
--- lib/Catalyst/Plugin/UploadProgress.pm       (revision 6455)
+++ lib/Catalyst/Plugin/UploadProgress.pm       (working copy)
@@ -41,8 +41,9 @@
      # if the URI is /progress?progress_id=<id> intercept the request
      # and display the progress JSON.

-    my $query = $c->req->uri->path_query;
-    if ( $query =~ /^\/progress\?progress_id=[a-f0-9]{32}$/ ) {
+    my $base  = $c->request->base;
+    my $query = $c->req->uri;
+    if ( $query =~ /^${base}progress\?progress_id=[a-f0-9]{32}$/ ) {
          return $c->upload_progress_output( $c->req->params-> 
{progress_id} );
      }

@@ -199,6 +200,21 @@
C::E::Apache2::MP20 1.07 with Apache 2.0.58, mod_perl 2.0.2 (OSX)
C::E::FastCGI with Apache 2.0.55, mod_fastcgi 2.4.2 (Ubuntu)
+=head2 NON-ROOT DEPLOYMENT
+
+By default, the javascript uses the URL /progress in order to check  
on the
+status of the upload. If you are deploying your application in a non- 
root
+location, like http://domain.com/myapp, you will also need to add an
+additional piece of javascript to your pages. This will let the  
progress
+checking javascript know the correct base path to use in the URL.
+
+If you are using Template Toolkit for your view, you can add the  
following to
+the <head> section of your pages.
+
+    <script type="text/javascript">
+        request_base = '[% Catalyst.request.base %]';
+    </script>
+
=head1 INTERNAL METHODS
You don't need to know about these methods, but they are documented
Index: lib/Catalyst/Plugin/UploadProgress/Static.pm
===================================================================
--- lib/Catalyst/Plugin/UploadProgress/Static.pm        (revision 6455)
+++ lib/Catalyst/Plugin/UploadProgress/Static.pm        (working copy)
@@ -122,6 +122,7 @@
__upload_progress_js__
var progress;
+var request_base = '/';
function startPopupProgressBar(form, options) {
      var id = generateProgressID();
@@ -203,7 +204,7 @@
function reportUploadProgress() {

-    url = '/progress?progress_id=' + progress.id;
+    url = request_base + 'progress?progress_id=' + progress.id;
      var req = new XMLHttpRequest();
      req.open('GET', url, Boolean(handleUploadProgressResults));
Index: Changes
===================================================================
--- Changes     (revision 6455)
+++ Changes     (working copy)
@@ -1,5 +1,7 @@
Revision history for Perl extension Catalyst::Plugin::UploadProgress
+        - Now works under non-root deployment.
+
0.03    2006-10-18 22:15:00
          - Handle race condition where progress handler is
            called before any upload data is received.
Index: example/Upload/root/static/js/progress.js
===================================================================
--- example/Upload/root/static/js/progress.js   (revision 6455)
+++ example/Upload/root/static/js/progress.js   (working copy)
@@ -1,5 +1,6 @@
var progress;
+var request_base = '/';
function startPopupProgressBar(form, options) {
      var id = generateProgressID();
@@ -81,7 +82,7 @@
function reportUploadProgress() {

-    url = '/progress?progress_id=' + progress.id;
+    url = request_base + 'progress?progress_id=' + progress.id;
      var req = new XMLHttpRequest();
      req.open('GET', url, Boolean(handleUploadProgressResults));



More information about the Catalyst mailing list