Skip to content

Instantly share code, notes, and snippets.

@amirasaran
amirasaran / fields.py
Last active June 11, 2017 10:46 — forked from yprez/fields.py
Django rest framework - Base64 image field
View fields.py
import base64
from django.core.files.base import ContentFile
from rest_framework import serializers
class Base64ImageField(serializers.ImageField):
def to_internal_value(self, data):
if isinstance(data, basestring) and data.startswith('data:image'):
# base64 encoded image - decode