Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##### truncated vhost config:
- server {
- location /upload {
- upload_pass @handler;
- upload_pass_args on;
- upload_pass_form_field "(.*)";
- upload_set_form_field name $upload_file_name;
- upload_set_form_field type $upload_content_type;
- upload_set_form_field path $upload_tmp_path;
- upload_store /tmp;
- }
- location @handler {
- lua_code_cache off;
- content_by_lua_file /path/to/upload.lua;
- }
- }
- ##### upload.lua:
- local ngx_form = require "form_parser_module"
- local params = {}
- local mb_conv = 1024 * 1024
- local post_defs = {}
- post_defs["content_type"] = ngx.var.http_content_type
- post_defs["content_length"] = ngx.var.http_content_length
- post_defs["maxinput"] = 2 * mb_conv
- post_defs["maxfilesize"] = 1 * mb_conv
- post_defs["args"] = params
- ngx.say("post defs:")
- for k, v in pairs( post_defs ) do
- ngx.say(k, ": ", v)
- end
- ret, post_args, tmpfiles = ngx_form.get_post_args(post_defs)
- if ret then
- ngx_form.removetmpfiles(tmpfiles)
- ngx.exit(500)
- end
- ngx.say("\npost args:")
- for k, v in pairs( post_args ) do
- ngx.say(k, ": ", v)
- end
- ngx.say("\n* request body:")
- ngx.say(ngx.req.get_body_data())
- ##### output:
- $ curl -F file=@TDXBN.gif http://localhost/upload
- * post defs:
- content_type: multipart/form-data; boundary=----------------------------ff78acc43147
- maxinput: 2097152
- content_length: 358
- maxfilesize: 1048576
- args:
- * post args:
- * request body:
- ------------------------------ff78acc43147
- ##### output of echo_request_body in location @handler:
- $ curl -F file=@TDXBN.gif http://localhost/upload
- ------------------------------a1c27b5f4c35
- Content-Disposition: form-data; name="name"
- TDXBN.gif
- ------------------------------a1c27b5f4c35
- Content-Disposition: form-data; name="type"
- image/gif
- ------------------------------a1c27b5f4c35
- Content-Disposition: form-data; name="path"
- /tmp/0009525769
- ------------------------------a1c27b5f4c35--
- ##### output of echo $request_body and echo $echo_request_body in location @handler:
- $ curl -F file=@TDXBN.gif http://localhost/upload
- ------------------------------69811337d604
- Content-Disposition: form-data; name="
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement