Nginx Upload Progress Module

nginx_uploadprogress_module is an implementation of an upload progress system, that monitors
RFC1867 POST upload as they are transmitted to upstream servers.

It works by tracking the uploads proxied by Nginx to upstream servers without
analysing the uploaded content and offers a web API to report upload progress in Javascript, JSON or configurable format.
It works because Nginx acts as an accelerator of an upstream server, storing uploaded POST content
on disk, before transmitting it to the upstream server. Each individual POST upload request
should contain a progress unique identifier.

upload_progress

This directive enables the upload progress module and reserve zone_size bytes to the zone_name which will be used to store the per-connection tracking information.

track_uploads

syntax:track_uploads <zone_name> <timeout>

default:n/a

context:location

This directive enables tracking uploads for the current location. Each POST landing in this location will register the request in the zone_name upload progress tracker.
Since Nginx doesn't support yet RFC 1867 upload, the location must be a proxy_pass or fastcgi location.
The POST must have a query parameter called X-Progress-ID (or an HTTP header of the same name) whose value is the unique identifier used to get progress information. If the POST has no such information, the upload will not be tracked.
The tracked connections are kept at most timeout seconds after they have been finished to be able to serve unseful information to upload progress probes.
WARNING: this directive must be the last directive of the location. It must be in a proxy_pass or fastcgi_pass location. Repeating the directive in a location will results in segfaults.

report_uploads

syntax:report_uploads <zone_name>

default:n/a

context:location

This directive allows a location to report the upload progress that is tracked by track_uploads for zone_name.
The returned document is a Javascript text with the possible 4 results by default:

the upload request hasn't been registered yet or is unknown:

new Object({ 'state' : 'starting' })

the upload request has ended:

new Object({ 'state' : 'done' })

the upload request generated an HTTP error

new Object({ 'state' : 'error', 'status' : <error code> })

One error code that can be of use to track for the client is 413 (request entity too large).

It is possible to return pure json instead of this javascript (see upload_progress_json_output).
It is also possible to configure completely the response format with the directive: upload_progress_template

The HTTP request to this location must have a X-Progress-ID parameter or HTTP header containing a valid unique identifier of an inprogress upload.

If you need to update the progress bar from a different domain or subdomain (cross domain), like if your upload server is different from your normal web server, you can try the JSONP protocol, like this: