Skip to content

Instantly share code, notes, and snippets.

@tkuchiki
Last active December 30, 2015 16:59
Show Gist options
  • Save tkuchiki/7858271 to your computer and use it in GitHub Desktop.
Save tkuchiki/7858271 to your computer and use it in GitHub Desktop.
nginx lua resty.upload (read http headers)
local resty_sha1 = require "resty.sha1"
local upload = require "resty.upload"
local chunk_size = 4096
local form = upload:new(chunk_size)
while true do
local typ, res, err = form:read()
ngx.say("### header 1")
ngx.say(res[1])
ngx.say(res[2])
ngx.say(res[3])
local file_name = string.match(res[2], "filename=\"(.+)\"")
ngx.say("file name : " .. file_name)
local typ, res, err = form:read()
ngx.say("### header 2")
ngx.say(res[1])
ngx.say(res[2])
ngx.say(res[3])
local img_type = string.match(res[2], "image/(.+)")
ngx.say("image type : " .. img_type)
end
# curl -F [email protected] http://localhost/xxx
### header 1
Content-Disposition
form-data; name="file"; filename="test.jpg"
Content-Disposition: form-data; name="file"; filename="test.jpg"
file name : test.jpg
### header 2
Content-Type
image/jpeg
Content-Type: image/jpeg
image type jpeg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment