fix upload file extract issue, add more test (#17)
* fix upload file extract issue, add more test * uncomment test
This commit is contained in:
+10
-8
@@ -23,10 +23,11 @@ while true do
|
|||||||
if typ == "header" then
|
if typ == "header" then
|
||||||
|
|
||||||
--"Content-Disposition","form-data; name=\"files[]\"; filename=\"Song-of-joy.png\""
|
--"Content-Disposition","form-data; name=\"files[]\"; filename=\"Song-of-joy.png\""
|
||||||
--"Content-Disposition","form-data; name=\"files[]\"; filename=\"rhythm-recognition-1.png\""
|
--"Content-Type","image\/png"
|
||||||
local key, val = res
|
local key = res[1]
|
||||||
if (key == "Content-Disposition") then
|
local val = res[2]
|
||||||
local ext = ngx.re.match(val, [[filename=".*\.(\w+)"]], "jo")
|
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)
|
file_name = string.format("%s/%s.%s", file_dir, uuid(), ext)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -45,10 +46,11 @@ while true do
|
|||||||
end
|
end
|
||||||
|
|
||||||
elseif typ == "part_end" then
|
elseif typ == "part_end" then
|
||||||
file:close()
|
if file then
|
||||||
|
file:close()
|
||||||
|
table.insert(files, file_name)
|
||||||
|
end
|
||||||
file = nil
|
file = nil
|
||||||
table.insert(files, file_name)
|
|
||||||
|
|
||||||
elseif typ == "eof" then
|
elseif typ == "eof" then
|
||||||
local http = require "resty.http"
|
local http = require "resty.http"
|
||||||
local httpc = http.new()
|
local httpc = http.new()
|
||||||
@@ -61,7 +63,7 @@ while true do
|
|||||||
host = "ngx"
|
host = "ngx"
|
||||||
},
|
},
|
||||||
body = {
|
body = {
|
||||||
cjson.encode({task_type = 1, data = files, created_by = 'ngx', updated_by = 'ngx'})
|
cjson.encode({task_type = 1, data = files})
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,7 +1,3 @@
|
|||||||
--local str = "form-data; name=\"files[]\"; filename=\"Song-of-joy.png\""
|
|
||||||
--local ext = ngx.re.match(str, [[filename=".*\.(\w+)"]], "jo")
|
|
||||||
--print(ext)
|
|
||||||
|
|
||||||
local magick = "/usr/local/ImageMagick/bin/magick"
|
local magick = "/usr/local/ImageMagick/bin/magick"
|
||||||
local tmp = io.open(magick,"r")
|
local tmp = io.open(magick,"r")
|
||||||
if tmp == nil then
|
if tmp == nil then
|
||||||
@@ -11,7 +7,7 @@ else
|
|||||||
io.close(tmp)
|
io.close(tmp)
|
||||||
end
|
end
|
||||||
print(magick)
|
print(magick)
|
||||||
--
|
|
||||||
--local origin = {
|
--local origin = {
|
||||||
-- "/Users/moicen/Music/alchemy/Song-of-joy.png",
|
-- "/Users/moicen/Music/alchemy/Song-of-joy.png",
|
||||||
-- "/Users/moicen/Music/alchemy/You-and-me.png"
|
-- "/Users/moicen/Music/alchemy/You-and-me.png"
|
||||||
@@ -22,4 +18,3 @@ print(magick)
|
|||||||
--local output = file:read("*all")
|
--local output = file:read("*all")
|
||||||
--file:close()
|
--file:close()
|
||||||
--ngx.say(output)
|
--ngx.say(output)
|
||||||
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
--local str = "form-data; name=\"files[]\"; filename=\"Song-of-joy.png\""
|
||||||
|
--local ext = ngx.re.match(str, [[filename=".*\.(\w+)"]], "jo")
|
||||||
|
--print(ext)
|
||||||
|
|
||||||
|
local str = [[image\/png]]
|
||||||
|
local ext = ngx.re.match(str, [[image\/(\w+)]])
|
||||||
|
print(ext)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user