4

I’m trying to post an image and a few nested parameters to an api using django rest framework. I’m trying to set up a curl with -F flags as discussed here with nested params as discussed here:

curl -X POST -S -H 'Accept: application/json' -F "customer[name]=foo&customer[email]=foo@bar.com&customer[zipcode]=1076AL&customer[city]=Amsterdam&customer[address]=foobar" -F "photo=@/Users/vincentvanleeuwen/Desktop/tmp/accord.jpg;type=image/jpg" http://localhost:8000/api/orders/

But I get the following response:

{"customer":{"city":["This field is required."],"email":["This field is required."],"zipcode":["This field is required."],"name":["This field is required."]}}

There seems to be something wrong with my nesting under the -F flag, as the nested variables work if I post it like this:

curl -X POST -S -H "Content-Type: application/json" -d '{"customer":{"name":"Adriaan","email":"adriaan@adriaan.com","zipcode":"1901ZP","address":"caravan","city":"Verweggistan"}}' http://localhost:8000/api/orders/

Any ideas what I’m doing wrong? Any help would be much appreciated!

Community
  • 1
  • 1
Vincent van Leeuwen
  • 681
  • 1
  • 9
  • 17

1 Answers1

2

Try separate -F flags for each parameter? From the curl manual:

Emulate a fill-in form with -F. Let's say you fill in three fields in a form. One field is a file name which to post, one field is your name and one field is a file description. We want to post the file we have written named "cooltext.txt". To let curl do the posting of this data instead of your favourite browser, you have to read the HTML source of the form page and find the names of the input fields. In our example, the input field names are 'file', 'yourname' and 'filedescription'.

    curl -F "file=@cooltext.txt" -F "yourname=Daniel" \
         -F "filedescription=Cool text file with cool text inside" \
         http://www.post.com/postit.cgi
montaigne
  • 141
  • 2
  • Thanks, I have it working now by using the separate -F flags, but had to change my models to avoid nesting parameters. Without the nesting it now works... – Vincent van Leeuwen Mar 12 '15 at 04:09