我是靠谱客的博主 拉长电源,这篇文章主要介绍openresty图片上传,现在分享给大家,希望可以做个参考。

用来处理图片上传的

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package.path = '/ebank/apps/openresty-web/lualib/resty/?.lua;' local upload = require "upload" local chunk_size = 4096 local form = upload:new(chunk_size) local file local filelen=0 form:set_timeout(0) -- 1 sec local filename function get_filename(res) local filename = ngx.re.match(res,'(.+)filename="(.+)"(.*)') if filename then return filename[2] end end local osfilepath = "/ebank/img/" local i=0 while true do local typ, res, err = form:read() if not typ then ngx.say("failed to read: ", err) return end if typ == "header" then if res[1] ~= "Content-Type" then filename = get_filename(res[2]) if filename then i=i+1 filepath = osfilepath .. filename file,err = io.open(filepath,"w") if not file then ngx.say("failed to open file ") ngx.log(ngx.ERR,err) return end else end end elseif typ == "body" then if file then filelen= filelen + tonumber(string.len(res)) file:write(res) else end elseif typ == "part_end" then if file then file:close() file = nil ngx.say("file upload success") end elseif typ == "eof" then break else end end if i==0 then ngx.say("please upload at least one file!") return end

将上面这个 savefile.lua 文件放到了 nginx/conf/lua/ 目录中
nginx.conf 配置文件中添加如下的配置 :
location /uploadfile
{
content_by_lua_file ‘conf/lua/savefile.lua’;
}

用下面的上传命令进行测试成功
curl -F “file=@abc.zip” http://127.0.0.1/uploadfile
注意lua-resty-upload模块只能上传有boundary的post请求体,没有boundary的话需要使用socket来进行传输。

http://blog.csdn.net/myslq/article/details/52484420

最后

以上就是拉长电源最近收集整理的关于openresty图片上传的全部内容,更多相关openresty图片上传内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(69)

评论列表共有 0 条评论

立即
投稿
返回
顶部