2017-09-01 181 views
1

我一直在嘗試使用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中。有沒有簡單的方法來上傳文件?

回答

1

找到解決方案。使用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()