diff --git a/prod/upload/upload.lua b/prod/upload/upload.lua index dc488f0..7ff1fc2 100644 --- a/prod/upload/upload.lua +++ b/prod/upload/upload.lua @@ -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}) }, } ) diff --git a/test/test_ngx.lua b/test/test_magick.lua similarity index 75% rename from test/test_ngx.lua rename to test/test_magick.lua index 529e108..3785568 100644 --- a/test/test_ngx.lua +++ b/test/test_magick.lua @@ -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 tmp = io.open(magick,"r") if tmp == nil then @@ -11,7 +7,7 @@ else io.close(tmp) end print(magick) --- + --local origin = { -- "/Users/moicen/Music/alchemy/Song-of-joy.png", -- "/Users/moicen/Music/alchemy/You-and-me.png" @@ -21,5 +17,4 @@ print(magick) --local file = io.popen("/usr/local/bin/magick convert -append " .. origin .. " /tmp/combined.jpeg" ) --local output = file:read("*all") --file:close() ---ngx.say(output) - +--ngx.say(output) \ No newline at end of file diff --git a/test/test_re.lua b/test/test_re.lua new file mode 100644 index 0000000..755e386 --- /dev/null +++ b/test/test_re.lua @@ -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) + + +