If I recall correctly, when I wrote the code to read uploaded files, it was
one chunk at a time (eg 4096 bytes).  Wouldn't this give you the
opportunity to stop at the right point?

take a look at github.com/appcove/AppStruct ...
Python/AppStruct/WSGI/Lib.py (or related, maybe werkseug.py) to see the
code.

Take care.
On Nov 24, 2011 1:48 PM, "Lisper" <ron.gar...@gmail.com> wrote:

> I'm trying to implement a limit on the size of uploaded files which
> depends on a user's status, i.e. a user who pays gets to upload larger
> files than one who doesn't.  I want to check the size of the upload BEFORE
> reading the data because I don't want to read 27 gigabytes only to find
> that this user is limited to 1MB.  I can't user Apache's LimitRequestBody
> directive.  The filtering has to be done within the application because
> it's the only part of the system that knows the user's status.
>
> I found this:
>
> http://mail.python.org/pipermail/web-sig/2008-November/003639.html
>
> which says:
>
> "If you use embedded mode, so long as your WSGI application doesn't
> read the input and just returns the error response, the request
> content wouldn't be read at all."
>
> So I tried this:
>
> def application(environ, start_response):
>  status = '200 OK'
>  headers = [('Content-type', 'text/html'),('Connection','close')]
>  out = start_response(status, headers)
>  out('--%s--<br>' % environ.get('CONTENT_LENGTH'))
>  return ['''<form method=post enctype="multipart/form-data">
>  <input name=f type=file>
>  <input type=submit></form>''']
>
> and ran it using:
>
>  WSGIScriptAlias /wsgitest /path/to/driver.wsgi
>  <location /wsgitest>
>  WSGIApplicationGroup %{GLOBAL}
>  </Location>
>
> which as far as I can tell should result in running in embedded mode.
>  This seems like it *should* display the size of the uploaded file without
> reading the file data.  However, empirically, the data is being read.  If I
> upload a large file, there's a long delay before getting a response.
>
> So what am I doing wrong?
>
> Thanks, and Happy Thanksgiving!
>
>  --
> You received this message because you are subscribed to the Google Groups
> "modwsgi" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/modwsgi/-/rEYG3K-zj74J.
> To post to this group, send email to modwsgi@googlegroups.com.
> To unsubscribe from this group, send email to
> modwsgi+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/modwsgi?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"modwsgi" group.
To post to this group, send email to modwsgi@googlegroups.com.
To unsubscribe from this group, send email to 
modwsgi+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/modwsgi?hl=en.

Reply via email to