【问题标题】:Upload image using lua使用lua上传图片
【发布时间】:2018-02-10 08:45:16
【问题描述】:
我一直在尝试使用 lua 和 Openresty Web 框架进行简单的图像上传。我找到了很多解决方案,例如
现在使用 lua-resty-post 我得到了表单数据,如何上传?
local resty_post = require 'resty.post'
local cjson = require 'cjson'
local post = resty_post:new()
local m = post:read()
ngx.say(cjson.encode(m))
由于我是 lua 新手,我不明白该使用哪一个。
我的要求很简单,我需要一个文件属性并想上传到某个地方,比如 php move_uploaded_file。有什么简单的上传文件的方法吗?
【问题讨论】:
标签:
file-upload
lua
luajit
openresty
【解决方案1】:
找到了解决方案。使用lua-resty-post。
上传.html
<form action="/uploadimage" method="post" enctype="multipart/form-data">
<input type="file" name="upload" accept="image/*">
<button>Upload</button>
</form>
nginx.conf
location /uploadimage {
content_by_lua_file image.lua;
}
image.lua
local resty_post = require "resty.post"
local post = resty_post:new({
path = "/my/path", -- path upload file will be saved
name = function(name, field) -- overide name with user defined function
return name.."_"..field
end
})
local m = post:read()