Nginx Upload Progress Module

Source: Internet
Author: User

Brief introduction

Nginxuploadprogressmodule is a module that can get the file upload progress, Official document: Httpuploadprogressmodule

Principle

Nginx as a proxy service, before the agent to the back-end service, the request content is cached to disk, through a unique identity of each upload, to get the size of the current server has been received.

Installation

1. Download the module via git or HTTP, address: Http://github.com/masterzen/nginx-upload-progress-module/tree/master

2. Compile into nginx with add-modue instructions

Instruction Set

Upload_progress

Syntax: upload_progress <zone_name> <zone_size>;

Context: http

Role: Reputation Nginx server uses upload progress module, reference named Zone_name, and allocates zone_size bytes space for upload status information

Track_uploads

Syntax: Track_uploads <zone_name> <timeout>;

Context: Location

Role: Fame This location uses the Upload_progress module to log file uploads, which must be located at the end of the configuration.

Report_uploads

Syntax: Report_uploads <zone_name>

Context: Location

Function: Allows a location to respond to the upload status, response content defaults to a JavaScript object with the new object, there are four states

Response:

Upload start (in preparation or request not arrived)

New Object ({"state": "Starting"})

Uploading now

New Object ({"state": "Uploading", "received": <size_received>, "size": <total_size>})

Upload Complete

New Object ({"state": "Done"})

Upload Error

New Object ({"state": "Error", "status": <error Code>})

Upload_progress_content_type

Syntax: Upload_progress_content_type <content-type>

Context: Location

Function: The content-type of the status response, the default is Test/javascript, can execute the JavaScript code

Upload_progress_header

Syntax: Upload_progress_header <progress-id>

Context: Location

Function: Modifies the name of the parameter (header) that identifies the upload ID, which defaults to X-progress-id

Upload_progress_jsonp_parameter

Syntax: Upload_progress_jsonp_parameter <callback_parameter>

Context: Location

Function: Modify the callback function name in JSONP form, the default value is "callback"

Upload_progress_json_output

Syntax: Upload_progress_json_output

Context: Location

Role: The reputation response output is in JSON format

Upload_progress_jsonp_output

Syntax: Upload_progress_jsonp_output

Context: Location

Function: The reputation response output is JSONP format

Upload_progress_template

Syntax: Upload_progress_template <state> <template>

Context: Location

Function: Output a response using a custom template

State Optional: Starting, uploading, error, done

Variables can be rendered in the template: $uploadprogress _length, $uploadprogress _received, $uploadprogress _status, $uploadprogress _callback

Example

http {#Reserve 1MB under the name ' Proxied ' to track uploadsupload_progress proxied 1m; server {Listen127.0.0.1default;        server_name localhost; Root/path/to/Root; Location/ {            #proxy to upstream serverProxy_pass http://127.0.0.1; Proxy_redirectdefault; #Track uploads in the ' proxied ' zone            #remember connections for 30s after they finishedtrack_uploads proxied 30s; } Location ^~/Progress {#Report uploads tracked in the ' proxied ' zonereport_uploads proxied; }    }}

Nginx Upload Progress Module

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.