title: Add values with curl inside a fileupload in a multipart form
body: <p><strong>My Goal</strong></p>
  
  <p>I try to automatically change some file on an embedded device over ethernet. To do this, I am creating a batch file to use on my computer which uses curl to send the POST for fileupload.</p>
  
  <p><strong>My Problem</strong></p>
  
  <p>Sadly I need some special values inside the "File-Part" of the multipart form. (name=uploadfile &amp; filename=index.htm) I know how to add more values to the multipart form, but I don't know how to add a value to the "File-Part" which is capsulated in the multipart form</p>
  
  <p><strong>My question</strong></p>
  
  <p>How can I add more information/values to the "File-Part" of an multipart form with curl? Is it even possible with curl from a batchfile?</p>
  
  <p>This is how the Request should look like:</p>
  
  <pre><code>POST /cgi-bin/fs_fileupload.cgi HTTP/1.1
  Host: 192.168.1.72
  User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0
  Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  Accept-Language: en-US,en;q=0.5
  Accept-Encoding: gzip, deflate
  DNT: 1
  Referer: http://192.168.1.72/files.html
  Connection: keep-alive
  Content-Length: 21930
  Content-Type: multipart/form-data; boundary=---------------------------86458141819368430751619760852
  
  -----------------------------86458141819368430751619760852
  Content-Disposition: form-data; name="uploadfile"; filename="index.htm"
  Content-Type: text/html
  
  &lt;html&gt;
  ...
  ...
  &lt;/html&gt;
  
  -----------------------------86458141819368430751619760852
  Content-Disposition: form-data; name="path"
  
  /
  -----------------------------86458141819368430751619760852
  Content-Disposition: form-data; name="submit"
  
  upload
  -----------------------------86458141819368430751619760852--
  </code></pre>
  
  <p>My embedded system needs those entries inside the "File-Part":</p>
  
  <blockquote>
    <p>Content-Disposition: form-data; name="uploadfile"; filename="index.htm"
    Content-Type: text/html</p>
  </blockquote>
  
  <p><strong>My Tries</strong></p>
  
  <p><strong><em>set as global multiform value:</em></strong></p>
  
  <blockquote>
    <p>curl -v -X POST -H "Expect:" -F "file=@index.htm;" -F path=/ -F submit=upload <a href="http://url/cgi-bin/fs_fileupload.cgi" rel="nofollow noreferrer">http://url/cgi-bin/fs_fileupload.cgi</a> --trace-ascii /dev/stdout</p>
  </blockquote>
  
  <p>This works from the curl side. I see the Values added to the POST on the Multipart Form level.</p>
  
  <pre><code>== Info:   Trying 192.168.1.72...
  == Info: TCP_NODELAY set
  == Info: Connected to 192.168.1.72 (192.168.1.72) port 80 (#0)
  =&gt; Send header, 211 bytes (0xd3)
  0000: POST /cgi-bin/fs_fileupload.cgi HTTP/1.1
  002a: Host: 192.168.1.72
  003e: User-Agent: curl/7.54.0
  0057: Accept: */*
  0064: Content-Length: 22084
  007b: Content-Type: multipart/form-data; boundary=--------------------
  00bb: ----18bc7d9c1cff49ca
  00d1: 
  =&gt; Send data, 153 bytes (0x99)
  0000: --------------------------18bc7d9c1cff49ca
  002c: Content-Disposition: form-data; name="file"; filename="index.htm
  006c: "
  006f: Content-Type: application/octet-stream
  0097:
  =&gt; Send data, 16384 bytes (0x4000)
  0000: &lt;html&gt;
  ...
  ...
  13de: &lt;/html&gt;
  =&gt; Send data, 452 bytes (0x1c4)
  0000:
  0002: --------------------------18bc7d9c1cff49ca
  002e: Content-Disposition: form-data; name="name"
  005b:
  005d: uploadfile
  0069: --------------------------18bc7d9c1cff49ca
  0095: Content-Disposition: form-data; name="filename"
  00c6:
  00c8: index.htm
  00d3: --------------------------18bc7d9c1cff49ca
  00ff: Content-Disposition: form-data; name="path"
  012c:
  012e: /
  0131: --------------------------18bc7d9c1cff49ca
  015d: Content-Disposition: form-data; name="submit"
  018c:
  018e: upload
  0196: --------------------------18bc7d9c1cff49ca--
  </code></pre>
  
  <p>But I need the values inside the "File-Part", because of the embedded system on the other side. When I do it like that, I end up with a file with the name index.htm and with the content index.htm except the real content! This is because of the Fileupload implementation on the Embedded device. And I don't have the possibility to cahnge that.</p>
  
  <p><strong><em>set inside file values:</em></strong></p>
  
  <blockquote>
    <p>curl -v -X POST -H "Expect:" -F "file=@index.htm;name=uploadfile;filename=index.htm" -F path=/ -F submit=upload <a href="http://%url%/cgi-bin/fs_fileupload.cgi" rel="nofollow noreferrer">http://%url%/cgi-bin/fs_fileupload.cgi</a> --trace-ascii /dev/stdout</p>
  </blockquote>
  
  <p>This gives me a warning from the curl side. And it also does not work on the embedded system side, because the needed values are missing.</p>
  
  <pre><code>Warning: skip unknown form field: name=uploadfile
  </code></pre>
  
  <p>More output</p>
  
  <pre><code>== Info:   Trying 192.168.1.72...
  == Info: TCP_NODELAY set
  == Info: Connected to 192.168.1.72 (192.168.1.72) port 80 (#0)
  =&gt; Send header, 211 bytes (0xd3)
  0000: POST /cgi-bin/fs_fileupload.cgi HTTP/1.1
  002a: Host: 192.168.1.72
  003e: User-Agent: curl/7.54.0
  0057: Accept: */*
  0064: Content-Length: 21875
  007b: Content-Type: multipart/form-data; boundary=--------------------
  00bb: ----07d21aa34b954425
  00d1:
  =&gt; Send data, 153 bytes (0x99)
  0000: --------------------------07d21aa34b954425
  002c: Content-Disposition: form-data; name="file"; filename="index.htm
  006c: "
  006f: Content-Type: application/octet-stream
  0097:
  =&gt; Send data, 16384 bytes (0x4000)
  0000: &lt;html&gt;
  ...
  ...
  13de: &lt;/html&gt;
  =&gt; Send data, 243 bytes (0xf3)
  0000:
  0002: --------------------------07d21aa34b954425
  002e: Content-Disposition: form-data; name="path"
  005b:
  005d: /
  0060: --------------------------07d21aa34b954425    
  008c: Content-Disposition: form-data; name="submit"
  00bb:
  00bd: upload
  00c5: --------------------------07d21aa34b954425--
  == Info: Recv failure: Connection was reset
  == Info: stopped the pause stream!
  == Info: Closing connection 0
  curl: (56) Recv failure: Connection was reset
  </code></pre>
  
  <p>This doesn't work. Curl tells me, it can not recognize my entered value. It doesn't work ether on the embedded side. The connection gets reseted because of the missing values!</p>