I am writing API, which accepts base64-encoded string and saves it as an image. It is trivial to do using standard library tools, such as base64, but how can I do it using viewsets.ModelViewSet? Which field should I modify? (I also have been trying to do it using custom middleware, but it is prohibited, since querydict cannot be modified)
1 Answer
You can use Base64ImageField from drf_extra_fields.
just add this in your serializer.
class YourImageSerializer(serializers.Serializer): img_field = Base64ImageField() you can also use this with ModelSerializer
check this out https://github.com/Hipo/drf-extra-fields
2 Comments
JohnShallow
Thank you for your suggestion! Should I modify standard django models.ImageField in my models.py file?
Jaspreet singh
You don't need to do any change with models. just add Base64ImageField in your serializer then it will accept base64 image string.