DRF-Base64 provides a set of serializers to handle Bas64-encoded files.
DRF-Base64 is compatible with python 2.7 and 3.4+ as well as Django 1.8+ and DRF 3.3+
pip install drf-base64
Within the source directory:
python setup.py install
DRF-Base64 provides a
Base64FileField and a
Base64ImageField very similar
ImageField with the added functionality of accepting
base64-encoded file strings as input.
If those serialiers receive an url (ie: when updating a record containing a file without
modifying that said file), it will leave the existing value untouched.
from rest_framework import serializers from base64.fields import Base64ImageField from .models import Product class ProductSerializer(serializers.ModelSerializer): picture = Base64ImageField(required=False) class Meta: model = Product ...
DRF-Base64 also provides a
ModelSerializer and an
also similar to DRF's own
HyperlinkedModelSerializer with the
added functionality of mapping
from drf_base64.serializers import ModelSerializer from .models import Product class ProductSerializer(ModelSerializer): class Meta: model = Product ...
If you'd like to enable base64 uploading of file for other field types than
ImageField, DRF-Base64 provides
Base64FieldMixin to let you do just that.
If you wish to use
Base64ImageField as default for model serializers
other than the ones provided, DRF-Base64 also provides
that you can apply on any other model serializer as long as they use
License information available here.
Contributors code of conduct is available here. Note that this COC will be enforced.