Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Maybrittnelson opened this issue May 7, 2019 · 0 comments

Comments

@Maybrittnelson
Copy link

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 Maybrittnelson changed the title How do I compress the data in the body If the uploaded file is a picture,I want it to be a 2048 by 2048 image with maximum height and width May 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant