I have made several apis in djangorestframework. This I could test both with the html form of the api as with curl in commandline.
Now I have an api to a Model with one off the fields an ImageField.
I can't figure out which curl command to use. Using the syntax I used before fot post actions in json format, it would be:
curl -X POST -S -H 'Content-Type: application/json' -u "username:password" --data-binary '{"otherfields":"something", "photo":"/home/michel/test.jpg"}' 127.0.0.1:8000/api/v1/
but in this case the photo will not be saved and left empty (the photo is an optional field)
adding -T /home/michel/test.jpg
I get an error message saying 127.0.0.1:800/api/v1/test.jpg does not exist as an url.
In the test html form of djangorestframework, all works fine.
Using the -F
option, it says I can only do 1 request at a time...
I also removed the datatype from data-binary
Can anybody help me how to make this curl post with both the image and the other data in json in 1 command.
$ curl -X POST -S -H "Accept-Language: en-en" -H 'Accept: application/json' \ -F "name=Avatar" \ -F "username=avatar" \ -F "password=A1234567" \ -F "[email protected]" \ -F "token=748e14e32ce165d06365d3c9a00cee3f" \ -F "avatar=@/home/moreno/Pictures/avatar004.jpg;type=image/jpg" 127.0.0.1:8000/api/v1/users/register/
response 400{"username":["This field is required."],"password":["This field is required."],"name":["This field is required."],"avatar":["No file was submitted."],"email":["This field is required."]}
– Margitmargo