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 form = upload:new(chunk_size)
|
||||||
-- local sha1 = resty_sha1:new()
|
-- local sha1 = resty_sha1:new()
|
||||||
uuid.seed()
|
uuid.seed()
|
||||||
ngx.say("...FILE UPLOAD...")
|
|
||||||
|
|
||||||
local file
|
local file
|
||||||
|
local file_name
|
||||||
|
local files = {}
|
||||||
while true do
|
while true do
|
||||||
local typ, res, err = form:read()
|
local typ, res, err = form:read()
|
||||||
|
|
||||||
@@ -20,9 +21,7 @@ while true do
|
|||||||
end
|
end
|
||||||
|
|
||||||
if typ == "header" then
|
if typ == "header" then
|
||||||
-- local file_name = my_get_file_name(res)
|
file_name = string.format("/tmp/%s.jpeg", uuid())
|
||||||
local file_name = string.format("/tmp/%s.jpeg", uuid())
|
|
||||||
ngx.say("...CREATE FILE....")
|
|
||||||
if file_name then
|
if file_name then
|
||||||
file = io.open(file_name, "w+")
|
file = io.open(file_name, "w+")
|
||||||
if not file then
|
if not file then
|
||||||
@@ -33,22 +32,36 @@ while true do
|
|||||||
|
|
||||||
elseif typ == "body" then
|
elseif typ == "body" then
|
||||||
if file then
|
if file then
|
||||||
ngx.say("...WRITE DATA...")
|
|
||||||
file:write(res)
|
file:write(res)
|
||||||
-- sha1:update(res)
|
-- sha1:update(res)
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif typ == "part_end" then
|
elseif typ == "part_end" then
|
||||||
ngx.say("...FINSIHED WRITTING FILE...")
|
|
||||||
file:close()
|
file:close()
|
||||||
file = nil
|
file = nil
|
||||||
|
table.insert(files, file_name)
|
||||||
-- local sha1_sum = sha1:final()
|
-- local sha1_sum = sha1:final()
|
||||||
-- sha1:reset()
|
-- sha1:reset()
|
||||||
-- my_save_sha1_sum(sha1_sum)
|
-- my_save_sha1_sum(sha1_sum)
|
||||||
|
|
||||||
elseif typ == "eof" then
|
elseif typ == "eof" then
|
||||||
-- todo weli : create task -> task_server -> generate_task()
|
local http = require "resty.http"
|
||||||
ngx.say("...NO MORE FILE...")
|
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
|
break
|
||||||
else
|
else
|
||||||
-- do nothing
|
-- do nothing
|
||||||
|
|||||||
Reference in New Issue
Block a user