filename in task should not contain folder info (#18)

reset filename to nil after file saved
This commit is contained in:
木逸辰
2021-09-11 19:44:16 +08:00
committed by GitHub
parent 3f98d5825d
commit fa8dea9e03
+4 -2
View File
@@ -28,11 +28,11 @@ while true do
local val = res[2] local val = res[2]
if key == "Content-Type" then if key == "Content-Type" then
local ext = ngx.re.match(val, [[(\w+)\/(\w+)]], "jo")[2] local ext = ngx.re.match(val, [[(\w+)\/(\w+)]], "jo")[2]
file_name = string.format("%s/%s.%s", file_dir, uuid(), ext) file_name = uuid() .. "." .. ext
end end
if file_name then if file_name then
file = io.open(file_name, "w+") file = io.open(file_dir .. "/" .. file_name, "w+")
if not file then if not file then
ngx.say("failed to open file ", file_name) ngx.say("failed to open file ", file_name)
return return
@@ -50,6 +50,8 @@ while true do
file:close() file:close()
table.insert(files, file_name) table.insert(files, file_name)
end end
-- 这里要重置一下file_name,否则后面的文件保存时会导致前面已保存的文件变成空文件
file_name = nil
file = nil file = nil
elseif typ == "eof" then elseif typ == "eof" then
local http = require "resty.http" local http = require "resty.http"