Mongrel Upload Progress Gotcha

Mongrel Upload Progress plugin is an awesome thing if you want to show upload progress bars. I have been using the plugin for about a year now to track progress of song uploads. However recently I wanted to track progress of reuploads and therefore started looking into tracking more than one action. Turns out that the plugin is actually designed to handle that. All you have to do is to change the :path_info config file in the config file From
    :path_info => '/files/upload', 
To
    :path_info => ['/files/reupload','/files/upload'],

With this modification, once you restart your mongrel it will start watching for uploads on /files/reupload too. However there is a small gotcha to lookout for if you are submitting your form to a url that looks like
/files/reupload/song_id
This won't work because mongrel will be watching out for /files/reupload and not /files/reupload/ If you look at the plugin code, it does the following to check whether it has to watchout for this action or not
return unless @path_info.include?(params['PATH_INFO']) &&
        params[Mongrel::Const::REQUEST_METHOD] == 'POST' &&
        upload_id = Mongrel::HttpRequest.query_parse(params['QUERY_STRING'])['upload_id']

where @path_info is an array created for :path_info line of the config file. Since the plugin checks for the exact path and not a regular expression even a trailing / can screw things up. I spent almost a day in figuring this out. Hope this post saves you sometime.

blog comments powered by Disqus