谢谢老师指点。已经成功读取到重构body后的数据。代码如下:
ngx.req.read_body()
local ContentType = ngx.req.get_headers()["Content-Type"]
local CT = ngx.re.match(ContentType,'(.+)boundary=(.+)',"iu")
local boundary = CT[2]
local body_data = ngx.req.get_body_data()
body_data = "--"..boundary.."\r\nContent-Disposition: form-data; name=\"number\"\r\n\r\n1\r\n"..body_data
local res = ngx.location.capture("/reco",{ method = ngx.HTTP_POST, body = body_data})
我把client_body_in_file_only clean关了,用ngx.req.get_body_data()来读取到body内容并进行重构。因为是POST图片(小于100k),所以还想请教下,如果从性能考虑,这种方法是否最优?
谢谢:)
2012/12/15 agentzh
<age...@gmail.com>
Hello!
2012/12/14 Dewey Du:
>
> 代码片段:
>
> ngx.req.read_body()
> local file = ngx.req.get_body_file()
> local ContentType = ngx.req.get_headers()["Content-Type"]
> ngx.req.set_header("Content-Type",ContentType)
> local body = ngx.encode_args({number=1,file="@"..file})
请注意,"@" 字符加文件名的上传记法是 curl 这样的客户端所特有的功能。这里并不支持这种记法。
如果你需要在 POST body 中把文件名展开文件的内容,需要自己在 Lua 中读取该文件的内容并传递给子请求。
Regards,
-agentzh