#2070: Large streaming uploads
----------------------------------------+-----------------------------------
Reporter: [EMAIL PROTECTED] | Owner: jacob
Status: assigned | Component: Core framework
Version: SVN | Resolution:
Keywords: streaming, upload, large | Stage: Accepted
Has_patch: 1 | Needs_docs: 0
Needs_tests: 0 | Needs_better_patch: 1
----------------------------------------+-----------------------------------
Comment (by anonymous):
Replying to [comment:27 Maniac <[EMAIL PROTECTED]>]:
> My idea of a hook is not fit into current middleware, I just wanted to
retain the style. So to clarify I see it like this.
>
> This can be a separate set of hooks similar to MIDDLEWARE_CLASSES or it
can be done in middleware classes themselves. To do the latter we will
specifiy that in addition to process_request, _response, _view and
_exception methods a middleware can define a new kind of method:
process_upload(request, data).
>
> parse_file_upload then would search for these middleware methods just as
http requests do in modpython.py and wsgi.py. The list of methods is
passed to a FieldStorage decendant that will call them each time it's
about to write a chunk of data to the target stream.
>
> This is it... Sorry I can't come with the actual code: pretty busy
rolling out my current project.
After reviewing all the comments, this one struck me in particular. I have
added a {{{process_upload(UploadException)}}} method to !MiddleWare.
I'm sure I might get heat for this recent addition, but I think it's the
cleanest way to allow extensibility.
Essentially, you can create a descriptor
for the {{{file_progress}}} attribute of {{{request}}}. It gets treated
like a dictionary so it will be passed things like {{{{'received':
1414,'size': 100000}}}} and is expected to return it when its asked for.
You are given an exception to raise if something should cancel the file
upload, so I could imagine someone writing a descriptor that would compare
{{{received}}} and some target size and cancel the upload if it's more
than that.
For more details, please look at {{{django/http/file_descriptor.py}}} for
the fallback descriptor. If you named that exact class
{{{process_upload}}} and stuck it in a middleware, it would be used (and
would work). I'll come up with another example soon, and stick it in
#4165.
--
Ticket URL: <http://code.djangoproject.com/ticket/2070#comment:125>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---