views:

48

answers:

1

I would like my Django application to decide whether to accept or reject an upload based on request headers and/or session data. If the upload is to be rejected, I would like the app to reset the connection rather than waste time receiving and storing the potentially large file that is going to be rejected anyway.

Django middleware looked promising, but on a close inspection it appears that by the time a request hits the middleware it's already too late, and the entire upload had been buffered somewhere (typically RAM or disk).

Are there any other hooks or settings I could use to achieve this?

+1  A: 

File upload handlers are the thingies you're looking for: http://docs.djangoproject.com/en/dev/topics/http/file-uploads/#modifying-upload-handlers-on-the-fly

Edit: After looking at file upload handler code it seems that it's passed only request.META, not the whole request object- this might or might not contain information what you need.

On the other hand- you could theoretically reconstruct session data from session id which is stored in cookie.

fest
romkyns