-- local resty_sha1 = require "resty.sha1" local upload = require "resty.upload" -- opm get thibaultcha/lua-resty-jit-uuid local uuid = require "resty.jit-uuid" local cjson = require "cjson" local chunk_size = 4096 local form = upload:new(chunk_size) -- local sha1 = resty_sha1:new() ngx.say("...FILE UPLOAD...") 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) local file_name = "/tmp/foo.jpeg" ngx.say("...CREATE FILE....") 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 ngx.say("...WRITE DATA...") file:write(res) -- sha1:update(res) end elseif typ == "part_end" then ngx.say("...FINSIHED WRITTING FILE...") file:close() file = nil -- local sha1_sum = sha1:final() -- sha1:reset() -- my_save_sha1_sum(sha1_sum) elseif typ == "eof" then ngx.say("...NO MORE FILE...") break else -- do nothing end end