add variable (#11)
* add variable * add nginx config file * update path
This commit is contained in:
+11
-12
@@ -1,27 +1,28 @@
|
||||
-- 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 task_server = ngx.var.task_server
|
||||
local file_dir = ngx.var.tmp_file_dir
|
||||
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
|
||||
ngx.say("failed to read: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
if typ == "header" then
|
||||
file_name = string.format("/tmp/%s.jpeg", uuid())
|
||||
file_name = string.format("%s/%s.jpeg", file_dir, uuid())
|
||||
ngx.log(ngx.ERR, "file name", file_name)
|
||||
if file_name then
|
||||
file = io.open(file_name, "w+")
|
||||
if not file then
|
||||
@@ -30,7 +31,7 @@ while true do
|
||||
end
|
||||
end
|
||||
|
||||
elseif typ == "body" then
|
||||
elseif typ == "body" then
|
||||
if file then
|
||||
file:write(res)
|
||||
-- sha1:update(res)
|
||||
@@ -40,19 +41,17 @@ while true do
|
||||
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 remote_url = string.format("%s/api/v1/ts/task_server/create_task", task_server)
|
||||
local res, err = httpc:request_uri(
|
||||
"http://127.0.0.1:8080/api/v1/ts/task_server/create_task",
|
||||
remote_url,
|
||||
{
|
||||
method = "POST",
|
||||
body = {
|
||||
cjson.encode({task_type = 1, data = files})
|
||||
cjson.encode({task_type = 1, data = files, created_by = 'openresty'})
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user