Created
March 20, 2013 16:25
-
-
Save benjaminbarbe/5206051 to your computer and use it in GitHub Desktop.
Example from https://github.com/agentzh/lua-resty-upload page
This file contains 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) | |
local sha1 = resty_sha1:new() | |
local file | |
while true do | |
local typ, res, err = form:read() | |
if not typ then | |
ngx.say("failed to read: ", err) | |
return | |
end | |
if typ == "header" then | |
local file_name = my_get_file_name(res) | |
if file_name then | |
file = io.open(file_name, "w+") | |
if not file then | |
ngx.say("failed to open file ", file_name) | |
return | |
end | |
end | |
elseif typ == "body" then | |
if file then | |
file:write(res) | |
sha1:update(res) | |
end | |
elseif typ == "part_end" then | |
file:close() | |
file = nil | |
local sha1_sum = sha1:final() | |
sha1:reset() | |
my_save_sha1_sum(sha1_sum) | |
elseif typ == "eof" then | |
break | |
else | |
-- do nothing | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hah! I would like to thank you for encouraging me, so I had few evenings with Lua and here is the result: https://github.com/pgaertig/nginx-big-upload