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

support decode the multipart form data as lua table #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Seayea
Copy link

@Seayea Seayea commented Jul 7, 2014

Add support of decoding the multipart form data as lua table.

By this feature, we can get the lua table which contains the fields from the submitted multipart form data; and operate on them within LUA script.

Currently, support the Content-Disposition and Content-Type header.

May submit more header support.

@atercattus
Copy link

It would be nice to check the content size before/in process decoding. And huge fields is better be saved to files, not in-memory table. May be something like this.

@agentzh
Copy link
Member

agentzh commented Jul 7, 2014

@Seayea I'm not sure if it is a good thing to have in this library. The whole point of this library is strict non-buffered processing of big upload data. If we add this full buffering API then we are actually encouraging the user to use the full-buffered processing method, which is very expensive.

@Seayea
Copy link
Author

Seayea commented Jul 8, 2014

@atercattus ,

Yeah. I think your comments will cover the cases which mainly aimed to upload files, and will save memory.
In my use case, I need to operate the file content directly. That's why I don't want to save the content as a file, open it, read it, close it and remove it.
It might be better to provide two APIs, which can provide raw content and as files.

@Seayea
Copy link
Author

Seayea commented Jul 8, 2014

@agentzh, I agree with you that this full-buffered way is expensive. I use this API just for files not so big. Maybe I should submit one more warning for using this API.

It's up to you to decide if this is valuable to be in the main track. I'm not sure as well if there is any more user's have the needs as me.

@agentzh
Copy link
Member

agentzh commented Jul 8, 2014

@Seayea I'll hold this for a little while until more users ask for it :) Thank you for the contribution!

@antonheryanto
Copy link

i think we should put this in another lua-resty-* like library and we are badly need something like bower or component which will scan github project which has something openresty.json to index the lua-resty packages, but with quality verified attribute as addition, imho.

@agentzh
Copy link
Member

agentzh commented Jul 8, 2014

@antonheryanto Yes, I agree we need a central place for 3rd-party lua-resty-* libraries :)

@bungle
Copy link
Member

bungle commented Nov 3, 2015

I have been using pjax (https://github.com/defunkt/jquery-pjax). The only supported way in pjax to post forms is throught JS FormData which is multipart/form-data. PHP does this so that you have $_FILES and $_POST separately. It stores uploads to tmp files. I think we could follow the same procedure. Although not here in lua-resty-upload, but in some other library. I will take a look at it.

@antonheryanto
Copy link

@bungle actually already handle that in my library lua-resty-post which convert application/x-www-form-urlencoded, application/json and multipart/form-data into lua table. it save file into temporary files (which path configurable) and provides info files info like PHP

@bungle
Copy link
Member

bungle commented Nov 4, 2015

@antonheryanto thanks for reminding about it. I wish I had remembered this yesterday, as I already went ahead and build a new one for my lua-resty-route project: https://github.com/bungle/lua-resty-route/blob/master/lib/resty/route/middleware/form.lua (that could be generalized). The code needs a bit cleaning up and support for json and urlencoded, but they are the easy part of this. Looks like we went almost the same route here, :-).

@bungle
Copy link
Member

bungle commented Nov 4, 2015

This is what I finally ended up:
https://github.com/bungle/lua-resty-reqargs/blob/master/lib/reqargs/reqargs.lua

There are room for improvements still (but I'll look those later):

  • max post files
  • max upload size per file
  • max post data size
  • more options what to load (only files, only post, only get)
  • maybe add cookie there are well

Looks very similar to @antonheryanto's lua-resty-post,

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

Successfully merging this pull request may close these issues.

6 participants