File upload 使用lua上传图像

File upload 使用lua上传图像,file-upload,lua,luajit,openresty,File Upload,Lua,Luajit,Openresty,我一直在尝试使用lua和openrestyweb框架上传简单的图像。我找到了很多解决方案,比如 使用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的新手,我不知道该

我一直在尝试使用lua和openrestyweb框架上传简单的图像。我找到了很多解决方案,比如

使用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之类的地方。有没有上传文件的简单方法?

找到了解决方案。使用

upload.html

<form action="/uploadimage" method="post" enctype="multipart/form-data">
  <input type="file" name="upload" accept="image/*">
  <button>Upload</button>
</form>
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()
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()