Using request.body_file is actually better than using body_file_raw. The raw reads directly from the underlying wsgi.input, which means if you are using wsgiref or some other server that doesn't correctly input terminate wsgi.input you may potentially deadlock reading forever because the wsgi.input may be directly connected to the remote socket, and if you read past CONTENT_LENGTH things go awry.
Using body_file it will wrap it into a LimitedLengthFile correctly and will do the right thing. Also, if you use something like pyramid_retry then it will have already made the wsgi.input seekable, using body_file will return the underlying file object anyway, so there is no reason to use body_file_raw. Request.body will consumes the whole body and returns it as a byte string, avoiding that is a good idea if it is a large upload. To make this message shorter: Tl;dr: Just use request.body_file, and have WebOb protect you from the crappy WSGI spec/WSGI servers as much as possible > On Apr 18, 2018, at 14:08, Jonathan Vanasco <[email protected]> wrote: > > I was confused on this years ago. The problem is in naming... > > `curl` is concerned with the HTTP method `POST`. Let's call that `HTTP > POST`. If you look at the `curl` documents for the difference on the various > `--data-XXXX` options. Those options will `HTTP POST` data in different > formats and encodings. > > WebOb's `request.POST` isn't the same as `HTTP POST` though; it's a > convenience method that pre-processing structured form data submissions via > `HTTP POST` (see > https://docs.pylonsproject.org/projects/webob/en/stable/api/request.html#webob.request.BaseRequest.POST) > > If you look at the source of webob's POST > https://github.com/Pylons/webob/blob/master/src/webob/request.py#L749-L797 > you'll see that it's trying to parse the raw data such as > `self.body_file_raw` and `self.body_file` into form values. > > Since your `HTTP POST` data isn't a form, you want to avoid all that > processing and just operate on the raw data. IIRC `body_file_raw` is better > for uploads, because it avoids reading/consuming the body (which may be a > stream instead of a static file). I default to `body_file_raw` out of habit. > > -- > You received this message because you are subscribed to the Google Groups > "pylons-discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected] > <mailto:[email protected]>. > To post to this group, send email to [email protected] > <mailto:[email protected]>. > To view this discussion on the web visit > https://groups.google.com/d/msgid/pylons-discuss/3d8848d6-87cc-4fab-9e46-eede7457e878%40googlegroups.com > > <https://groups.google.com/d/msgid/pylons-discuss/3d8848d6-87cc-4fab-9e46-eede7457e878%40googlegroups.com?utm_medium=email&utm_source=footer>. > For more options, visit https://groups.google.com/d/optout > <https://groups.google.com/d/optout>. -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/10070E30-EA82-4D88-8BD0-2165E627EBFC%400x58.com. For more options, visit https://groups.google.com/d/optout.
