2

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 1

6

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your suggestion! Should I modify standard django models.ImageField in my models.py file?
You don't need to do any change with models. just add Base64ImageField in your serializer then it will accept base64 image string.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.