upload_cleanup

The 'upload_cleanup' directive specifies the cleanup of uploaded files after they have been processed.

Syntaxupload_cleanup on | off | [conditions];
Defaultnone
Contexthttp, server, location, if in location, limit_except
Arguments1+

Description

The upload_cleanup directive is used in the NGINX upload module to control the cleanup behavior for uploaded files after processing. When enabled, it ensures that any temporary files created during the file upload process are removed once they are no longer needed. This is particularly important for optimizing storage and preventing unnecessary disk space usage, especially when handling large file uploads. The directive can be set within different contexts such as http, server, or location, and can accept one or more arguments that configure how the cleanup should be handled.

The directive can take multiple values, where the parameter specifies conditions under which the cleanup occurs. When set, it allows the server to automatically manage temporary files created during uploads, thus reducing the overhead of managing these files manually. This not only ensures that storage is effectively managed but also that sensitive data does not linger longer than necessary after processing. It's particularly useful in environments where high volumes of uploads are processed, as it minimizes the risk of accumulating stale files in the file system over time.

Config Example

server {
    location /upload {
        upload_pass /upload_handler;
        upload_cleanup on;
        upload_store /tmp/uploads;
    }
}

Ensure that the cleanup directive is properly set in contexts where file uploads are handled, or the desired cleanup behavior may not occur.

Be mindful of setting conditions that might inadvertently prevent deletions of important files if not configured correctly.

← Back to all directives