http-upload #

A module for nginx for handling file uploads using multipart/form-data encoding (RFC 1867) and resumable uploads according to this protocol.

Source: upstream source

Directives

upload_add_header #

syntax: upload_add_header 2 args;  ·  context: http, server, location, location-if, limit_except

Specifies the name and content of the header that will be added to the response

upload_aggregate_form_field #

syntax: <code><b>upload_aggregate_form_field</b> <i>name</i> <i>value</i></code><br>  ·  default: —<br>  ·  context: server,location

Specifies a form field(s) containing aggregate attributes to generate for each uploaded file in request body passed to backend. Both name and value could contain standard nginx variables, variables from following additional special variables: The value of a field specified by this directive is evaluated after resources to calculate MD5 and SHA1 checksums.

upload_buffer_size #

syntax: <code><b>upload_buffer_size</b> <i>size</i></code><br>  ·  default: size of memory page in bytes<br>  ·  context: server,location

Size in bytes of write buffer which will be used to accumulate file data and write it to disk. This directive is intended to be used to compromise memory usage vs. syscall rate.

upload_cleanup #

syntax: <code><b>upload_cleanup</b> <i>status/range</i> ...</code><br>  ·  default: —<br>  ·  context: server,location

Specifies HTTP statuses after generation of which all file successfuly uploaded in current request will be removed. Used for cleanup after backend or server failure. Backend may also explicitly signal errornous status if it doesn't need uploaded files for some reason. HTTP status must be a numerical value in range 400-599, no leading zeroes are

upload_empty_fiels_names #

syntax: upload_empty_fiels_names on | off (on/off flag);  ·  context: http, server, location, location-if, limit_except

Specifies whether empty field names are allowed

upload_limit_rate #

syntax: <code><b>upload_limit_rate</b> <i>rate</i></code><br>  ·  default: 0<br>  ·  context: main,server,location

Specifies upload rate limit in bytes per second. Zero means rate is unlimited.

upload_max_file_size #

syntax: <code><b>upload_max_file_size</b> <i>size</i></code><br>  ·  default: 0<br>  ·  context: main,server,location

Specifies maximal size of the file. Files longer than the value of this directive will be omitted. This directive specifies "soft" limit, in the sense, that after encountering file longer than specified limit, nginx will continue to process request body, trying to receive remaining files. For "hard" limit client_max_body_size directive must be

upload_max_output_body_len #

syntax: <code><b>upload_max_output_body_len</b> <i>size</i></code><br>  ·  default: 100k<br>  ·  context: main,server,location

Specifies maximal length of the output body. This prevents piling up of non-file form fields in memory. Whenever output body overcomes specified limit error 413 (Request entity too large) will be generated. The value of zero for this directive specifies that no restrictions on output body length should be applied.

upload_max_part_header_len #

syntax: <code><b>upload_max_part_header_len</b> <i>size</i></code><br>  ·  default: 512<br>  ·  context: server,location

Specifies maximal length of part header in bytes. Determines the size of the buffer which will be used to accumulate part headers.

upload_merge_buffer_size #

syntax: upload_merge_buffer_size 1 arg (size (k/m/g));  ·  context: http, server, location

Specifies the size of buffer, which will be used for merging ranges into state file

upload_pass #

syntax: <code><b>upload_pass</b> <i>location</i></code><br>  ·  default: —<br>  ·  context: server,location

Specifies location to pass request body to. File fields will be stripped and replaced by fields, containing necessary information to handle uploaded files.

upload_pass_args #

syntax: <code><b>upload_pass_args</b> on | off</code><br>  ·  default: off<br>  ·  context: main,server,location

Enables forwarding of query arguments to location, specified by In this example backend gets request URI "/upload?id=5". In case of upload_pass_args off backend gets "/upload".

upload_pass_form_field #

syntax: <code><b>upload_pass_form_field</b> <i>regex</i></code><br>  ·  default: —<br>  ·  context: server,location

Specifies a regex pattern for names of fields which will be passed to backend from original request body. This directive could be specified multiple times per location. Field will be passed to backend as soon as first pattern matches. For PCRE-unaware enviroments this directive specifies exact name of a field to pass to backend. If directive is

upload_range_header_buffer_size #

syntax: upload_range_header_buffer_size 1 arg (size (k/m/g));  ·  context: http, server, location

Specifies the size of buffer, which will be used for returning range header

upload_resumable #

syntax: <code><b>upload_resumable</b> on | off</code><br>  ·  default: upload_resumable off<br>  ·  context: main,server,location

Enables resumable uploads.

upload_set_form_field #

syntax: <code><b>upload_set_form_field</b> <i>name</i> <i>value</i></code><br>  ·  default: —<br>  ·  context: server,location

Specifies a form field(s) to generate for each uploaded file in request body passed to backend. Both name and value could contain following special variables: with leading path elements in DOS and UNIX notation stripped. I.e. "D:\\Documents And Settings\\My Dcouments\\My Pictures\\Picture.jpg" will be converted to "Picture.jpg" and "/etc/passwd" will be

upload_state_store #

syntax: <code><b>upload_state_store</b> <i>directory</i> [<i>level1</i> [<i>level2</i>]] ...</code><br>  ·  default: —<br>  ·  context: server,location

Specifies a directory that will contain state files for resumable uploads. The directory could be hashed. In this case all subdirectories should exist before starting nginx.

upload_store #

syntax: <code><b>upload_store</b> <i>directory</i> [<i>level1</i> [<i>level2</i>]] ...</code><br>  ·  default: —<br>  ·  context: server,location

Specifies a directory to which output files will be saved to. The directory could be hashed. In this case all subdirectories should exist before starting nginx.

upload_store_access #

syntax: <code><b>upload_store_access</b> <i>mode</i></code><br>  ·  default: upload_store_access user:rw<br>  ·  context: server,location

Specifies access mode which will be used to create output files.

upload_tame_arrays #

syntax: <code><b>upload_tame_arrays</b> on | off</code><br>  ·  default: off<br>  ·  context: main,server,location

Specifies whether square brackets in file field names must be dropped (required for PHP arrays).

Example

server {
    client_max_body_size 100m;
    listen 80;

    # Upload form should be submitted to this location
    location /upload/ {
        # Pass altered request body to this location
        upload_pass @test;

        # Store files to this directory
        # The directory is hashed, subdirectories 0 1 2 3 4 5 6 7 8 9 should exist
        upload_store /tmp 1;

        # Allow uploaded files to be read only by user
        upload_store_access user:r;

        # Set specified fields in request body
        upload_set_form_field $upload_field_name.name "$upload_file_name";
        upload_set_form_field $upload_field_name.content_type "$upload_content_type";
        upload_set_form_field $upload_field_name.path "$upload_tmp_path";

        # Inform backend about hash and size of a file
        upload_aggregate_form_field "$upload_field_name.md5" "$upload_file_md5";
        upload_aggregate_form_field "$upload_field_name.size" "$upload_file_size";

        upload_pass_form_field "^submit$|^description$";

        upload_cleanup 400 404 499 500-505;
    }

    # Pass altered request body to a backend
    location @test {
        proxy_pass http://localhost:8080;
    }
}

↑ back to index