문제

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?

도움이 되었습니까?

해결책

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"}}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top