upload_pass

The upload_pass directive specifies a location to which the request body is forwarded after uploading files.

Syntaxupload_pass ;
Defaultnone
Contexthttp, server, location, if in location, limit_except
Arguments1

Description

The upload_pass directive is part of the NGINX upload module, which facilitates the handling of file uploads through multipart/form-data encoding. When a client uploads files, the NGINX server stores these files in a temporary directory specified by the upload_store directive. After storing the files, the contents of the request body are modified: all file fields are removed and replaced with new fields that contain essential metadata regarding the uploaded files. This modified request is then forwarded to the location specified in the upload_pass directive, allowing further processing of the request without the original file contents.

It is crucial to understand that the upload_pass directive functions under the constraint of certain request methods. It is primarily designed to handle POST requests. If a request method other than POST is encountered, the module will return a 405 (Method Not Allowed) error. This behavior can be modified through the use of the error_page directive to redirect unsupported methods to another handler. Additionally, the use of the upload_pass directive requires a well-defined structure in conjunction with other directives, such as upload_store, to ensure that the uploaded files are properly managed and processed in the specified location, promoting efficient file handling and integration into existing application workflows.

Config Example

location /upload {
    upload_pass /handle_upload;
    upload_store /tmp/uploads;
}

Ensure the specified location in upload_pass is correctly defined and can handle the request after file upload.

Do not use upload_pass with request methods that are not POST unless you handle them specifically with error_page.

Confirm that the upload_store directive is set correctly, as file uploads will be stored in the defined directory before passing the request.

← Back to all directives