开发者

How to refuse an upload before it completes in Django?

开发者 https://www.devze.com 2022-12-17 03:32 出处:网络
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 conn

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 l开发者_开发问答ooked 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号