8👍
Try this:
cars[0][car_img_1]:car_img_file1
cars[1][car_img_2]:car_img_file2
You can insert it in “bulk-edit” mode.
1👍
I found this answer from this problem. Edited as per your code.
Convert your Image Fields to base64Image and send it through the JSON data.
All you need to do is:
- go to https://www.base64-image.de/ and convert the image to base64 format. Copy the encoded result.
- Install
django-extra-fields
package in your project from here - In your
serializer_class
, import and change the image field toBase64ImageField
:
serializers.py
...
from drf_extra_fields.fields import Base64ImageField
...
- Now, go to your
postman
and send the JSON data like the following. Remember to send that encoded image in yourimage
field in JSON.
{
"name":"John",
"age":30,
"cars":
{
"car_img_1":"<base64 encoded image>",
"car_img_2":"<base64 encoded image>",
"car_img_3":"<base64 encoded image>"
}
}
Source:stackexchange.com