Using HTTP cURL to post JSON data with an image file

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@address.com", "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?


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_address=email@address.com" -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
链接地址: http://www.djcxy.com/p/8586.html

上一篇: 通过requestJS POST请求发送JSON对象和图像文件的数组

下一篇: 使用HTTP cURL将JSON数据与图像文件一起发布