From fa8dea9e030ce021bc7db60f85d09edcd940cbca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=A8=E9=80=B8=E8=BE=B0?= Date: Sat, 11 Sep 2021 19:44:16 +0800 Subject: [PATCH] filename in task should not contain folder info (#18) reset filename to nil after file saved --- prod/upload/upload.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/prod/upload/upload.lua b/prod/upload/upload.lua index 7ff1fc2..b6f176b 100644 --- a/prod/upload/upload.lua +++ b/prod/upload/upload.lua @@ -28,11 +28,11 @@ while true do 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) + file_name = uuid() .. "." .. ext end if file_name then - file = io.open(file_name, "w+") + file = io.open(file_dir .. "/" .. file_name, "w+") if not file then ngx.say("failed to open file ", file_name) return @@ -50,6 +50,8 @@ while true do file:close() table.insert(files, file_name) end + -- 这里要重置一下file_name,否则后面的文件保存时会导致前面已保存的文件变成空文件 + file_name = nil file = nil elseif typ == "eof" then local http = require "resty.http"