fix upload file extract issue, add more test (#17)

* fix upload file extract issue, add more test

* uncomment test
This commit is contained in:
木逸辰
2021-09-09 11:13:07 +08:00
committed by GitHub
parent 3d2e03be82
commit 3f98d5825d
3 changed files with 22 additions and 15 deletions
+10 -8
View File
@@ -23,10 +23,11 @@ while true do
if typ == "header" then
--"Content-Disposition","form-data; name=\"files[]\"; filename=\"Song-of-joy.png\""
--"Content-Disposition","form-data; name=\"files[]\"; filename=\"rhythm-recognition-1.png\""
local key, val = res
if (key == "Content-Disposition") then
local ext = ngx.re.match(val, [[filename=".*\.(\w+)"]], "jo")
--"Content-Type","image\/png"
local key = res[1]
local val = res[2]
if key == "Content-Type" then
local ext = ngx.re.match(val, [[(\w+)\/(\w+)]], "jo")[2]
file_name = string.format("%s/%s.%s", file_dir, uuid(), ext)
end
@@ -45,10 +46,11 @@ while true do
end
elseif typ == "part_end" then
file:close()
if file then
file:close()
table.insert(files, file_name)
end
file = nil
table.insert(files, file_name)
elseif typ == "eof" then
local http = require "resty.http"
local httpc = http.new()
@@ -61,7 +63,7 @@ while true do
host = "ngx"
},
body = {
cjson.encode({task_type = 1, data = files, created_by = 'ngx', updated_by = 'ngx'})
cjson.encode({task_type = 1, data = files})
},
}
)