upload_aggregate_form_field

The `upload_aggregate_form_field` directive allows multiple file uploads to be aggregated into a single form field in the request body.

Syntaxupload_aggregate_form_field field_name aggregate_filenames;
Defaultnone
Contexthttp, server, location, if in location, limit_except
Arguments2

Description

The upload_aggregate_form_field directive is part of the NGINX upload module, which provides functionality for handling file uploads using multipart/form-data encoding. This directive specifically enables the aggregation of uploaded files into a single form field, allowing multiple files to be treated as a single entity in the request. This is useful in scenarios where an application needs to process several files together, such as when a user submits multiple images that should be stored in a single array field or processed as a collection.

This directive takes two parameters: the name of the form field to aggregate files into and a flag to specify whether to include the original filenames when processing the aggregated files. When enabled, NGINX will create a single form field entry that contains the combined data of all uploaded files, which can then be accessed by the backend application as a single field in the parsed request body. This aggregation behavior helps simplify the processing logic in applications that need to handle bulk uploads while still adhering to the multipart/form-data standard.

It is important to place this directive in the appropriate context, such as within the http, server, or location blocks, to ensure it applies to the desired location for file uploads. Configurations that involve nested contexts, such as within an if in location, can also effectively handle more complex use cases, although care should be taken to avoid complications associated with conditional processing in NGINX.

Config Example

location /upload {
    upload_pass /upload_process;
    upload_aggregate_form_field files aggregate; 
}

Ensure that the field name and aggregation logic are consistent with backend expectations.

When using aggregate filenames, confirm that your backend can interpret the resulting format correctly.

Placement in the configuration context is crucial; incorrect placement may lead to unintended behavior.

← Back to all directives