colintherobot
colintherobot

Reputation: 157

multipart POST with nested params cUrl

I'm trying to test making a post request with cURL passing a file into nested params, but having a hard time getting the flags/ordering correct:

curl -i -H "Authorization: <access_str>" -H "Accept: application/json"
 -H "Content-Type: application/json" -X POST -d '{"data": {"photo": 
"@/Users/colin/Desktop/mastiff.jpg"} }' localhost:3000/api/v1/blah/blah

I feel like I either need a --data-binary or -F or both maybe? The server is just getting the nested params as a string and not as a multipart file

{"data"=>{"photo"=>"@/Users/colin/Desktop/mastiff.jpg"}

Upvotes: 3

Views: 927

Answers (1)

colintherobot
colintherobot

Reputation: 157

curl -i -H "Authorization: <access_str>" -X POST -F
'data[photo]=@/Users/colin/Desktop/mastiff.jpg'
localhost:3000/api/v1/data/data/data 

Don't even need to specify that it's JSON. Next step is trying to pass two photos in the same field. The problem now is that passing a second file results in a massive binary string.

Upvotes: 1

Related Questions