【问题标题】: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()
    

    【讨论】:

      猜你喜欢
      • 2018-01-16
      • 2021-03-19
      • 2015-12-25
      • 2015-07-11
      • 2013-11-03
      • 2017-08-03
      • 2015-02-10
      • 2016-06-07
      相关资源
      最近更新 更多