2017-09-01 8 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)) 

私はluaを初めて使用しているため、どちらを使用するかわかりません。 私の要件は非常に単純です、私はファイル属性が必要で、PHPのようにいくつかの場所にアップロードしたいmove_uploaded_file。ファイルをアップロードする簡単な方法はありますか?

答えて

1

解決策が見つかりました。 lua-resty-postを使用します。

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() 
nginx.conf

upload.html

<form action="/uploadimage" method="post" enctype="multipart/form-data"> 
    <input type="file" name="upload" accept="image/*"> 
    <button>Upload</button> 
</form> 

関連する問題