Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm not sure what you're expecting your second curl command to do, but I'm pretty sure it's not doing what you want. If you give more than one <code>--data</code> or <code>-d</code> parameters to curl, their values will be joined together, separated by <code>&amp;</code>.</p> <p>For example, if you have a file <code>test.txt</code> with contents <code>This is a test.</code> and you do request like this: </p> <pre><code>curl -i -X POST -H Accept:application/json -H Content-Type:application/json \ -d '{file:{filename:"test.txt",md5sum:"ab3d2f"}}' \ --data-binary @test.txt 'http://localhost:4567/upload/test.txt' </code></pre> <p>This is what the request looks like:</p> <pre><code>POST /upload/test.txt HTTP/1.1 User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5 Host: localhost:4567 Accept:application/json Content-Type:application/json Content-Length: 61 {file:{filename:"test.txt",md5sum:"ab3d2f"}}&amp;This is a test. </code></pre> <p>The request body is not valid JSON. It's not valid URL-encoded form data or multi-part form data either.</p> <p>It's not obvious how to combine JSON requests with file uploads. Here are some options:</p> <ul> <li>Just use <code>multipart/form-data</code>. That is, do what you're doing right now with your Ruby code and <code>-F</code> option to curl. </li> <li>Use <code>multipart/form-data</code> with one part of JSON for metadata and other part with the raw uploaded file.</li> <li>Embed the file into JSON by base64-encoding it.</li> <li>Do some kind of two-request workflow where first you post the metadata as JSON and then you upload the file in the POST body.</li> </ul> <p>I'd probably go with the first option, because it's so widely supported.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload