Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can this work with ngx.req.get_post_args() #14

Open
ryannining opened this issue Mar 28, 2015 · 3 comments
Open

Can this work with ngx.req.get_post_args() #14

ryannining opened this issue Mar 28, 2015 · 3 comments

Comments

@ryannining
Copy link

I have some code like this

    ngx.ctx.uploads={} --m.getupload()
    ngx.req.read_body()
    ngx.ctx.posts={}
    args, err = ngx.req.get_post_args()
    for key, val in pairs(args) do
        ngx.ctx.posts[key]=val
        ngx.ctx.gets[key]=val

and m.getupload is using your library, to get all the uploads into table hashed by the input_name. it also save the non file data input to table posts

getupload:->
    form = upload\new(100000)
    file_name=""
    input_name=""
    resx=""
    result={}
    while form~=nil do
      typ, res, err = form\read()
      if typ == "header" then
        if res[1]=="Content-Disposition"
          tt=m.getfield(res)
          file_name = tt.filename
          input_name = tt.name
          resx=""

      elseif typ == "eof"
        break  
      elseif typ == "body"
        if input_name
          resx=resx..res

      elseif typ == "part_  "
        if file_name
          result[input_name]={file_name,resx}
          ngx.ctx.gets[input_name]=file_name
        else
          ngx.ctx.gets[input_name]=resx

        resx=""

if i enable uploads processing then the ngx.req.get_post_args() not work. perhaps i need to detect the enc-type multipart ?

@agentzh
Copy link
Member

agentzh commented Mar 28, 2015

@ryannining Yes, you need to test the MIME type before taking any action. lua-resty-upload implements its own request body reader while ngx.req.read_body() uses nginx's request body reader.

@ryannining
Copy link
Author

Still cant find how to test the mime, please help me

@agentzh
Copy link
Member

agentzh commented Mar 28, 2015

@ryannining You can just try calling resty.upload's new() method first. Which performs the MIME test. If the test fails, new() returns nil with an error string.

Under the hood, it just checks the Content-Type request header.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants