Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RequestDataTooBig Request body exceeded settings.DATA_UPLOAD_MAX_MEMORY_SIZE

Tags:

python

django

I'm trying to send a base64 encoded image from a client to a django server , but when an image is bigger than 2.5 MB I'm getting :

Request body exceeded settings.DATA_UPLOAD_MAX_MEMORY_SIZE.
Request body exceeded settings.DATA_UPLOAD_MAX_MEMORY_SIZE.
Request body exceeded settings.DATA_UPLOAD_MAX_MEMORY_SIZE.
Request body exceeded settings.DATA_UPLOAD_MAX_MEMORY_SIZE.
Request body exceeded settings.DATA_UPLOAD_MAX_MEMORY_SIZE.
Request body exceeded settings.DATA_UPLOAD_MAX_MEMORY_SIZE.
Request body exceeded settings.DATA_UPLOAD_MAX_MEMORY_SIZE.
Request body exceeded settings.DATA_UPLOAD_MAX_MEMORY_SIZE.

Traceback (most recent call last):
File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in run
self.result = application(self.environ, self.start_response)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/handlers.py", line 63, in __call__
return self.application(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 170, in __call__
response = self.get_response(request)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 124, in get_response
response = self._middleware_chain(request)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/exception.py", line 41, in inner
response = response_for_exception(request, exc)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/exception.py", line 76, in response_for_exception
response = debug.technical_500_response(request, *sys.exc_info(), status_code=400)
File "/usr/local/lib/python2.7/dist-packages/django/views/debug.py", line 84, in technical_500_response
html = reporter.get_traceback_html()
File "/usr/local/lib/python2.7/dist-packages/django/views/debug.py", line 316, in get_traceback_html
c = Context(self.get_traceback_data(), use_l10n=False)
File "/usr/local/lib/python2.7/dist-packages/django/views/debug.py", line 293, in get_traceback_data
'filtered_POST': self.filter.get_post_parameters(self.request),
File "/usr/local/lib/python2.7/dist-packages/django/views/debug.py", line 167, in get_post_parameters
return request.POST
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 128, in _get_post
self._load_post_and_files()
File "/usr/local/lib/python2.7/dist-packages/django/http/request.py", line 310, in _load_post_and_files
self._post, self._files = QueryDict(self.body, encoding=self._encoding), MultiValueDict()
File "/usr/local/lib/python2.7/dist-packages/django/http/request.py", line 268, in body
raise RequestDataTooBig('Request body exceeded settings.DATA_UPLOAD_MAX_MEMORY_SIZE.')
RequestDataTooBig: Request body exceeded settings.DATA_UPLOAD_MAX_MEMORY_SIZE.
[31/Dec/2016 12:33:50] "POST /chat_photo/ HTTP/1.1" 500 59

I don't know how can i send a big photo like 3-4 MB .

like image 528
Cosmin Oprea Avatar asked Dec 31 '16 12:12

Cosmin Oprea


2 Answers

Just add Following line in your settings.py

DATA_UPLOAD_MAX_MEMORY_SIZE = 5242880 #whatever size you want to gave i have given 5MB

By default DATA_UPLOAD_MAX_MEMORY_SIZE is 2.5MB

You can see by default global settings values from django.conf.global_settings

like image 99
jahmed31 Avatar answered Nov 17 '22 13:11

jahmed31


This is django induced check to avoid any Suspicious activity.

https://docs.djangoproject.com/en/dev/ref/settings/#data-upload-max-memory-size

like image 23
Bipul Jain Avatar answered Nov 17 '22 12:11

Bipul Jain