Advertisement
Guest User

Untitled

a guest
Nov 26th, 2011
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. ##### truncated vhost config:
  2.  
  3. server {
  4. location /upload {
  5. upload_pass @handler;
  6. upload_pass_args on;
  7. upload_pass_form_field "(.*)";
  8. upload_set_form_field name $upload_file_name;
  9. upload_set_form_field type $upload_content_type;
  10. upload_set_form_field path $upload_tmp_path;
  11. upload_store /tmp;
  12. }
  13.  
  14. location @handler {
  15. lua_code_cache off;
  16. content_by_lua_file /path/to/upload.lua;
  17. }
  18. }
  19.  
  20.  
  21. ##### upload.lua:
  22.  
  23. local ngx_form = require "form_parser_module"
  24. local params = {}
  25. local mb_conv = 1024 * 1024
  26. local post_defs = {}
  27.  
  28. post_defs["content_type"] = ngx.var.http_content_type
  29. post_defs["content_length"] = ngx.var.http_content_length
  30. post_defs["maxinput"] = 2 * mb_conv
  31. post_defs["maxfilesize"] = 1 * mb_conv
  32. post_defs["args"] = params
  33.  
  34. ngx.say("post defs:")
  35. for k, v in pairs( post_defs ) do
  36. ngx.say(k, ": ", v)
  37. end
  38.  
  39. ret, post_args, tmpfiles = ngx_form.get_post_args(post_defs)
  40. if ret then
  41. ngx_form.removetmpfiles(tmpfiles)
  42. ngx.exit(500)
  43. end
  44.  
  45. ngx.say("\npost args:")
  46. for k, v in pairs( post_args ) do
  47. ngx.say(k, ": ", v)
  48. end
  49.  
  50. ngx.say("\n* request body:")
  51. ngx.say(ngx.req.get_body_data())
  52.  
  53.  
  54. ##### output:
  55.  
  56. $ curl -F file=@TDXBN.gif http://localhost/upload
  57. * post defs:
  58. content_type: multipart/form-data; boundary=----------------------------ff78acc43147
  59. maxinput: 2097152
  60. content_length: 358
  61. maxfilesize: 1048576
  62. args:
  63.  
  64. * post args:
  65.  
  66. * request body:
  67. ------------------------------ff78acc43147
  68.  
  69.  
  70. ##### output of echo_request_body in location @handler:
  71.  
  72. $ curl -F file=@TDXBN.gif http://localhost/upload
  73. ------------------------------a1c27b5f4c35
  74. Content-Disposition: form-data; name="name"
  75.  
  76. TDXBN.gif
  77. ------------------------------a1c27b5f4c35
  78. Content-Disposition: form-data; name="type"
  79.  
  80. image/gif
  81. ------------------------------a1c27b5f4c35
  82. Content-Disposition: form-data; name="path"
  83.  
  84. /tmp/0009525769
  85. ------------------------------a1c27b5f4c35--
  86.  
  87.  
  88. ##### output of echo $request_body and echo $echo_request_body in location @handler:
  89.  
  90. $ curl -F file=@TDXBN.gif http://localhost/upload
  91. ------------------------------69811337d604
  92. Content-Disposition: form-data; name="
  93.  
  94.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement