lua-resty-upload icon indicating copy to clipboard operation
lua-resty-upload copied to clipboard

If the uploaded file is a picture,I want it to be a 2048 by 2048 image with maximum height and width

Open Maybrittnelson opened this issue 6 years ago • 0 comments

while true do
	local typ, res, err = form:read()
	if not typ then
		ngx.say("failed to read: ", err)
		return
	end
	if typ == "header" then
		local key = res[1]
		local value = res[2]
		if key == "Content-Disposition" then
		local kvlist = string.split(value, ';')
			for _, kv in ipairs(kvlist) do
				local seg = string.trim(kv)
				if seg:find("filename") then
					local kvfile = string.split(seg, "=")
					local filename = string.sub(kvfile[2], 2, -2)
					if filename then
						ext = getExtension(filename)
						local now = os.date("%Y%m%d%H%M%S", os.time())
						local filename = now.."-"..string.sub(ngx.md5(now..user_cid), 0, 8)..ext
						local image_id = ""
						if string.find(uri, "/upload/photo") then
							uri = string.gsub(ngx.var.uri, '/upload/photo', "/bfs/g/"..filename)
							image_id = "/g/"..filename
						elseif string.find(uri, "/upload/voice") then
							uri = string.gsub(ngx.var.uri, '/upload/voice', "/bfs/v/"..filename)
						else 
							ngx.print(cjson.encode({code=404, message="Not Found"}))
							ngx.exit(404)
						end
						break
					end
				end
			end
		end
	--append body
	elseif typ == "body" then
		if res then
				appender = appender..res
		end
	--one file has been read
	elseif typ == "part_end" then
		if appender ~= '' then
			-- If the uploaded file is a picture,I want it to be a 2048 by 2048 image with maximum height and width
			code = upload2BFS(uri, data)

Maybrittnelson avatar May 07 '19 02:05 Maybrittnelson