-1

I am using DRF for mobile application. now I want to set the maximum data limit that client side can sent to POST api. How can i set that limit in DRF (django rest framework)?

I found this post but i need in more details.

Update:

also referred this . Added DATA_UPLOAD_MAX_MEMORY_SIZE = 3*1024*1024 in settings.py file and hit POST api with 5.6MB payload data, still its accepting that data.

108
  • 119
  • 2
  • 11
  • There is a Django setting for limiting request size `DATA_UPLOAD_MAX_MEMORY_SIZE` https://docs.djangoproject.com/en/3.1/ref/settings/#data-upload-max-memory-size – Iain Shelvington Feb 25 '21 at 07:00

2 Answers2

2

In setting.py add

DATA_UPLOAD_MAX_MEMORY_SIZE=10*1024*1024

Default size is 2621440 (i.e. 2.5 MB) // 2.510241024

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

Pranav Mundre
  • 129
  • 1
  • 5
  • I tried using this but it is not giving any error. I used this in settings.py file "DATA_UPLOAD_MAX_MEMORY_SIZE = 3*1024*1024". and wrote request.data in function still its accepting it – 108 Feb 25 '21 at 11:12
0

According to comments in this issue on DRF's Github, the DATA_UPLOAD_MAX_MEMORY_SIZE setting suggested in other answers is not respected by DRF because of the way DRF reads the requests, so it seems that there is no obvious easy solution for this.

One possible solution of integrating checks for this setting into DRF's parsers is presented in a comment in the linked github issue. I suppose you could write custom parsers that implement the necessary checking (for more info on writing and using custom parsers see https://www.django-rest-framework.org/api-guide/parsers/).

zet0x
  • 21
  • 3