title: using curl for multipart/form-data with a file upload
body: <p>I have a server API that I have developed against the format used by Fiddler to do HTTP posts of files, which is a multipart/form-data post. I'm trying to get curl to do something similar (so I can stop using Fiddler for testing and instead have a separate program call out to curl programmatically).</p>
  
  <p>Here is how it's set up in Fiddler, which is what I need to replicate. The file being uploaded is myfile.html:</p>
  
  <pre><code>---------------------------acebdf13572468
  Content-Disposition: form-data; name="fieldNameHere"; filename="myfile.html"
  Content-Type: text/html
  
  &lt;@INCLUDE *C:\myfiles\myfile.html*@&gt;
  ---------------------------acebdf13572468--
  </code></pre>
  
  <p>So what I need is for curl to produce something similar: in particular the name= part, followed by the file content at the bottom of this part. I've tried this with:</p>
  
  <pre><code>curl -F "fieldNameHere=myfile.html" http://myapi.com/
  </code></pre>
  
  <p>When I do that it seems to totally ignore my file though. Here's the verbose output if I add -v:</p>
  
  <pre><code>POST / HTTP/1.1
  User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.27.1 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
  Host: perl-h4.factset.io
  Accept: */*
  Content-Length: 166
  Expect: 100-continue
  Content-Type: multipart/form-data; boundary=----------------------------981301fdaeb3
  </code></pre>
  
  <p>There's no file content at all (it's a large HTML file). So I think there might be something fundamental I'm missing here. Any pointers would be quite welcome.</p>
  
  <p>Also, I have checked other StackOverflow questions like this: <a href="https://stackoverflow.com/questions/19116016/what-is-the-right-way-to-post-multipart-form-data-using-curl">What is the right way to POST multipart/form-data using curl?</a></p>
  
  <p>But they are basically saying to do something like what I'm doing here. So maybe the problem is not my syntax, but some other reason it doesn't want to read the file.</p>