Max Image Upload size Validation Django REST API
Asked Answered
L

1

5

I am using Django and Django Rest Framework. How to validate the image size of the image posted to django rest framework api ?

This is a bit confusing :

FILE_UPLOAD_MAX_MEMORY_SIZE = #something

The maximum size, in bytes, for files that will be uploaded into memory. Files larger than FILE_UPLOAD_MAX_MEMORY_SIZE will be streamed to disk. Defaults to 2.5 megabytes.

I set this to 255 and even then I was able to upload a 2MB image from django admin. I want to reject the POST request and raise error if image size is larger than 5MB

Loreenlorelei answered 13/8, 2015 at 6:15 Comment(0)
C
11

FILE_UPLOAD_MAX_MEMORY_SIZE defines the maximum size a file can reach in memory before being streamed to disk. This is an optimization for uploading files. It does not limit the maximum file size that can be uploaded.

While this doesn't answer your question I hope it clears up your confusion about the setting.

Cozy answered 15/10, 2015 at 16:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.