when i use the mouble,i occured a probole.it will be more than one \r in each line.my lua script:
package.path = 'E:/nginx-windows/lua/?.lua;E:/nginx-windows/resty/?.lua;'
package.cpath = 'E:/nginx-windows/?.dll;'
local restyUpload = require "upload"
local chunk_size = 4096
local file
local filelen=0
local filename
local args = ngx.req.get_query_args()
--ngx.say(args)
function get_filename(res)
local filename = ngx.re.match(res,'(.+)filename="(.+)"(.*)')
if filename then
return filename[2]
end
end
local rootDir = "e:/temp/"
local filepath = rootDir .. "/" --args.path ..
local temp = io.open(filepath)
local form = restyUpload:new(chunk_size)
if form == nil then
ngx.log(ngx.ALERT, "parse body failed.")
ngx.exit(500)
end
form:set_timeout(0) -- 1 sec
local i=0
ngx.header.content_type = "text/plain"
while true do
local typ, res, err = form:read()
if not typ then
ngx.say("failed to read body: ", err)
return
end
if typ == "header" then
if res[1] ~= "Content-Type" then
filename = get_filename(res[2])
if filename then
i=i+1
filepath = filepath .. filename
file = io.open(filepath,"w+")
if not file then
ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
ngx.log(ngx.ALERT, "can not open file: "..filepath)
return
end
end
end
elseif typ == "body" then
ngx.say("type", res);
if file then
--filelen= filelen + tonumber(string.len(res))
file:write(res)
end
elseif typ == "part_end" then
if file then
file:close()
file = nil
ngx.say("success")
end
elseif typ == "eof" then
break
else
end
end
if i==0 then
ngx.exit(ngx.HTTP_NOT_FOUND)
ngx.log(ngx.ALERT, "please upload at least one file!")
return
end
so,when i try to use this script to upload image、zip、doc and other files ,all files are damage.and i found that not all files will damage,same file is right.
when i use the mouble,i occured a probole.it will be more than one \r in each line.my lua script:
the response is:
but,the file is:
so,when i try to use this script to upload image、zip、doc and other files ,all files are damage.and i found that not all files will damage,same file is right.