2

I am using django-rest-framework and I have a registration form that accepts some data which includes an image file of the user.

How can I emulate this using cURL? I can post JSON data like the following:

curl -i -X POST -H "Content-Type: application/json" -d '{"email_address":"[email protected]", "password": "Password", "display_name": "mark", "full_name": "Mark", "gender": "M", "date_of_birth": "1955-05-05", "location_id": "3"}' http://localhost/register

How can I add an image field to this form?

1
  • Not a direct answer to your question, but I highly recommend you check out the Postman REST Client for Chrome. While it isn't useful for command-line scripting, this plugin is great for trying out your REST interface during development. Commented Nov 25, 2014 at 16:39

1 Answer 1

3

The way to do this is to completely remove the -d option and to replace with subsequent -F options for each field required. Here is an example:

curl -i -F "[email protected]" -F "password=password" -F "display_name=mark10" -F "full_name=Mark Ten" -F "gender=M" -F "date_of_birth=1955-01-01" -F "location_id=3" -F "profile_picture=@/path/to/pic.jpg" http://localhost:1989/api/rest/v1/register
Sign up to request clarification or add additional context in comments.

2 Comments

Why I got the error: curl: (26) couldn't open file "/path/to/pic.jpg" ? thanks!
Permissions or the file doesn't exist? Or maybe the file is locked?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.