Last active
December 30, 2015 16:59
-
-
Save tkuchiki/7858271 to your computer and use it in GitHub Desktop.
nginx lua resty.upload (read http headers)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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