-- 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() uuid.seed() local file local file_name local files = {} 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 file_name = string.format("/tmp/%s.jpeg", uuid()) 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 table.insert(files, file_name) -- local sha1_sum = sha1:final() -- sha1:reset() -- my_save_sha1_sum(sha1_sum) elseif typ == "eof" then local http = require "resty.http" local httpc = http.new() local res, err = httpc:request_uri( "http://127.0.0.1:8080/api/v1/ts/task_server/create_task", { method = "POST", body = { cjson.encode({task_type = 1, data = files}) }, } ) if 201 ~= res.status then ngx.log(ngx.ERR, "create task failed", err) ngx.say(err) ngx.exit(res.status) end ngx.say(res.body) break else -- do nothing end end