Skip to content

Instantly share code, notes, and snippets.

@dented
Created July 26, 2016 17:11
Show Gist options
  • Save dented/2f88eca8de30167b1d357689af43a27d to your computer and use it in GitHub Desktop.
Save dented/2f88eca8de30167b1d357689af43a27d to your computer and use it in GitHub Desktop.
Nginx Upload Module Chunked
# See http://wiki.nginx.org/HttpUploadModule
location = /upload-restore-archive {
# if resumable uploads are on, then the $upload_field_name variable
# won't be set because the Content-Type isn't (and isn't allowed to be)
# multipart/form-data, which is where the field name would normally be
# defined, so this *must* correspond to the field name in the Rails view
set $upload_field_name "archive";
# location to forward to once the upload completes
upload_pass /backups/archives/restore.json;
# filesystem location where we store uploads
#
# The second argument is the level of "hashing" that nginx will perform
# on the filenames before storing them to the filesystem. I can't find
# any documentation online, so as an example, say we were using this
# configuration:
#
# upload_store /tmp/uploads 2 1;
#
# A file named '43829042' would be written to this path:
#
# /tmp/uploads/42/0/43829042
#
# I hope that's clear enough. The argument is required and must be
# greater than 0. You can see the implementation here:
#
# http://lxr.evanmiller.org/http/source/core/ngx_file.c#L118
upload_store /backup/upload 1;
# whether uploads are resumable
upload_resumable on;
# access mode for storing uploads
upload_store_access user:r;
# maximum upload size (0 for unlimited)
upload_max_file_size 0;
# form fields to be passed to Rails
upload_set_form_field $upload_field_name[filename] "$upload_file_name";
upload_set_form_field $upload_field_name[path] "$upload_tmp_path";
upload_set_form_field $upload_field_name[content_type] "$upload_content_type";
upload_aggregate_form_field $upload_field_name[size] "$upload_file_size";
# hashes are not supported for resumable uploads
# https://github.com/vkholodkov/nginx-upload-module/issues/12
#upload_aggregate_form_field $upload_field_name[signature] "$upload_file_sha1";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment