I have a form that sends an image via Django Rest Framework. The serializer is as shown:
class AvatarSerializer(serializers.ModelSerializer):
avatar = Base64ImageField(validators=[image_validation])
class Meta:
model = Profile
fields = ('avatar',)
I also have image validation that checks the size of the image so that it is not over 12MB:
def image_validation(image):
# 12MB
MAX_FILE_SIZE = 12000000
print(image.name)
if image.size > MAX_FILE_SIZE:
print(image.size)
raise ValidationError("File size too big!")
The image size gets printed out when I try to upload an image greater than 12mb, however, I get this response in Chrome's network tab: Failed to load response data
I read that it might be because of the image's size (I was trying to upload a 30mb image). The ValidationError
is not shown and the user gets a 500 server error. How can I fix this?
django-extra-fields
forBase64ImageField
?Base64ImageField