Reputation: 88499
Assume I have some data as below,
{
"name":"John",
"age":30,
"cars":
{
"car_img_1":"car_img_file1",
"car_img_2":"car_img_file2",
"car_img_3":"car_img_file3"
}
}
How can I send it using POSTMAN
with form-data
?
NOTES
1. car_img_fileX
will be the file(.jpg
,.png
etc types)
2. What I'd tried -->> POSTMAN Screenshot.
3. Local server builted with Django framework
Current Output
Receiving 5 different items/data instaed of Nested data--> see this Pycharm Debugger Output
Upvotes: 13
Views: 10211
Reputation: 37
To anyone who's still facing this issue, This is how I ended up solving it. after you select the form-data tab, click on bulk edit and enter your values as below:
depreciation_details[method]:Straight-line
depreciation_details[rate]:2
depreciation_details[salvage_value]:100000
depreciation_details[useful_life]:4
or you can enter the values directly into the fields provided as shown in the screenshot below:
so with the original post, this is what it should be:
cars[car_img_1]:car_img_file1
cars[car_img_2]:car_img_file2
Upvotes: 1
Reputation: 1
I searched this functionality in Postman and found your this question. When i try this answer nothing worked. But i changed key pointing and tried remove the "." after indexing my key's (cars[0].car_img_1 -> cars[0]car_img_1).
So my solution this:
Upvotes: 0
Reputation: 21
You should try in this way (Hint: Watch carefully form-data key names):
Upvotes: 1
Reputation: 119
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:
django-extra-fields
package in your project from hereserializer_class
, import and change the image field to Base64ImageField
:serializers.py
...
from drf_extra_fields.fields import Base64ImageField
...
postman
and send the JSON data like the following. Remember to send that encoded image in your image
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>"
}
}
Upvotes: 1
Reputation: 3718
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.
Upvotes: 8