使用lua上传图片

问题描述:

我一直在尝试使用lua和Openresty web框架进行简单的图片上传。我发现很多解决方案,如使用lua上传图片

使用Lua-resty-后我得到的表单数据,现在我怎么上传?

local resty_post = require 'resty.post' 
local cjson = require 'cjson' 

local post = resty_post:new() 
local m = post:read() 
ngx.say(cjson.encode(m)) 

由于我是新手,我不明白哪一个使用。 我的要求非常简单,我需要一个文件属性,并希望在某些地方上传,如在php move_uploaded_file中。有没有简单的方法来上传文件?

找到解决方案。使用lua-resty-post

upload.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()