解决nginx + lua 上传文件问题
来源:互联网 发布:免费流量软件 移动 编辑:程序博客网 时间:2024/06/06 00:19
本文的原文连接是: http://blog.csdn.net/freewebsys/article/details/49509123 未经博主允许不得转载。
博主地址是:http://blog.csdn.net/freewebsys
1,首先不能创建upload对象
直接报错
failed to new upload: request body already exists
参考这个博客:
http://my.oschina.net/timingbob/blog/164231
就是request body 不能被使用2次造成的。
因为之前使用过一个叫 lua_need_request_body 显示 respons的post信息,和这个冲突了。去掉就好了。
这个博客上面有详细写,如何将post信息写到日志里面。
http://blog.csdn.net/jom_ch/article/details/15359129
去掉就好了。
2,将上传日志写到磁盘
参考:http://blog.csdn.net/langeldep/article/details/9628819
上面已经写的很详细了。
package.path = '/usr/local/share/lua/5.1/?.lua;/usr/local/openresty/lualib/resty/?.lua;'package.cpath = '/usr/local/lib/lua/5.1/?.so;'local upload = require "upload"local chunk_size = 4096 --如果不设置默认是4096.local form = upload:new(chunk_size)local filelocal filelen=0form:set_timeout(0) -- 1 seclocal filenamefunction get_filename(res) local filename = ngx.re.match(res,'(.+)filename="(.+)"(.*)') if filename then return filename[2] endendlocal osfilepath = "/usr/local/openresty/nginx/html/"local i=0while 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 = io.open(filepath,"w+") if not file then ngx.say("failed to open file ") 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 endendif i==0 then ngx.say("please upload at least one file!") returnend
这里需要注意一个问题,
/usr/local/openresty/nginx/html/文件夹必须是nobody权限,否则不能写文件,报错。
chown nobody:nobody /usr/local/openresty/nginx/html
上传啥都行了,也可以是图片,文件。
3,总结
本文的原文连接是: http://blog.csdn.net/freewebsys/article/details/49509123 未经博主允许不得转载。
博主地址是:http://blog.csdn.net/freewebsys
lua+nginx上传速度还是非常快的。而且很轻量。
0 0
- 解决nginx + lua 上传文件问题
- Nginx+upload+lua 简单的文件上传
- 设置nginx的client_max_body_size解决nginx+php上传大文件的问题
- nginx的client_max_body_size解决nginx+php上传大文件的问题
- 通过设置nginx的client_max_body_size解决nginx+php上传大文件的问题
- 通过设置nginx的client_max_body_size解决nginx+php上传大文件的问题
- 通过设置nginx的client_max_body_size解决nginx+php上传大文件的问题
- nginx基于lua-resty-upload实现文件上传
- nginx+tomcat架构 文件上传 文件上传进度问题
- nginx文件上传遇到的意外问题
- codeigniter解决新文件上传问题&&文件上传问题
- JSP实现文件上传,解决上传文件名为乱码问题
- 如何解决nginx上传大文件的限制?
- flex 解决上传文件中文名字问题
- 解决PHP大文件上传问题
- 使用autoit解决webdriver文件上传问题
- Android 文件上传,解决NetworkOnMainThreadException问题!
- 解决上传文件中文乱码问题
- Leetcode129: Combination Sum II
- 机器学习(十四)SVM总结
- eclipse导入Android项目报错的解决方法
- iwpriv
- sqlite3自增key设定(创建自增字段)
- 解决nginx + lua 上传文件问题
- extern用法详解(转)
- 三、HBase(V0.94.27)安装(完全分布式)
- JAVA的 WebService规范 JAX-WS实现例子
- 量化交易-1
- Coding Guidelines for Cocoa
- <iOS>获取键盘高度
- jQuery-easyUI的使用:combogrid
- 利用UIWebView打造一个炫酷的视频背景视图(OC & Swift)