request task_server to create task after file saved (#8)
This commit is contained in:
+21
-8
@@ -8,9 +8,10 @@ local chunk_size = 4096
|
||||
local form = upload:new(chunk_size)
|
||||
-- local sha1 = resty_sha1:new()
|
||||
uuid.seed()
|
||||
ngx.say("...FILE UPLOAD...")
|
||||
|
||||
local file
|
||||
local file_name
|
||||
local files = {}
|
||||
while true do
|
||||
local typ, res, err = form:read()
|
||||
|
||||
@@ -20,9 +21,7 @@ while true do
|
||||
end
|
||||
|
||||
if typ == "header" then
|
||||
-- local file_name = my_get_file_name(res)
|
||||
local file_name = string.format("/tmp/%s.jpeg", uuid())
|
||||
ngx.say("...CREATE FILE....")
|
||||
file_name = string.format("/tmp/%s.jpeg", uuid())
|
||||
if file_name then
|
||||
file = io.open(file_name, "w+")
|
||||
if not file then
|
||||
@@ -33,22 +32,36 @@ while true do
|
||||
|
||||
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
|
||||
table.insert(files, file_name)
|
||||
-- local sha1_sum = sha1:final()
|
||||
-- sha1:reset()
|
||||
-- my_save_sha1_sum(sha1_sum)
|
||||
|
||||
elseif typ == "eof" then
|
||||
-- todo weli : create task -> task_server -> generate_task()
|
||||
ngx.say("...NO MORE FILE...")
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user