Question

I need post file and JSON object to API (Ruby On Rails) by curl in one request. My request looks like this:

curl --data @file.pdf -H "Accept: application/json" -H "Content-Type: multipart/form-data"  -X POST -d '{"document":{"name":"file name"}}' http://localhost:3000/api/documents

But Rails parse it bad. Params on the server:

Parameters: {"{\"document\":{\"name\":\"file name\"}}"=>nil}

Where is problem?

Was it helpful?

Solution

You should pass multipart/form-data (as you specify), not a JSON string. Try this:

-d 'document[name]=file name'

Result on my machine:

Parameters: {"document"=>{"name"=>"file name"}}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top