On Wed, Dec 5, 2012 at 6:18 PM, Salforis wrote:
> 你是怎么传的?我只知道用ngx.req.get_body_data,还有其他方法吗?
>
一个常见的错误是你在调用 ngx.req.get_body_data() 之前没有调用 ngx.req.read_body() 函数。
如果你确实调用了 ngx.req.read_body(),但 ngx.req.get_body_data() 仍然返回
nil,此时则很可能是因为请求体的大小因为超出了你的 client_body_buffer_size 的配置从而被缓冲到了临时文件中,见:
http://wiki.nginx.org/HttpCoreModule#client_body_buffer_size
此时你可以进一步调用 ngx.req.get_body_file() 得到该临时文件路径,然后在 Lua 中读取此文件的内容,见
http://wiki.nginx.org/HttpLuaModule#ngx.req.get_body_file
如果你压根不想让请求体被缓冲到文件系统,则可以在 nginx.conf 配置文件中将 client_body_buffer_size
设置成和 client_max_body_size 一样大,见:
http://wiki.nginx.org/HttpCoreModule#client_max_body_size
当然,如果你希望需要流式地读取请光体,则不应使用 ngx.req.read_body(), ngx.req.get_body_data()
或者 ngx.req.get_body_file(),而应当使用 ngx.req.socket():
http://wiki.nginx.org/HttpLuaModule#ngx.req.socket
Best regards,
-agentzh