Skip to content

Instantly share code, notes, and snippets.

@benjaminbarbe
Created March 20, 2013 16:25
Show Gist options
  • Save benjaminbarbe/5206051 to your computer and use it in GitHub Desktop.
Save benjaminbarbe/5206051 to your computer and use it in GitHub Desktop.
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
@pgaertig
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment