title: Set content-length header on individual parts of a multipart/form-data upload
body: <p>I would like to upload multiple files using a post request of type <code>multipart/form-data</code> and for each file I need to know the file size (content-length) on the server side.</p>
  
  <p>To construct the <code>POST</code> request in <code>javascript</code> I use a <code>FormData</code> object and append the File objects for the upload to it. This works fine, but only a <code>Content-type</code> header is added to each part, in addition to the <code>Content-Disposition</code> header, but no <code>Content-length</code> header, though this information is available from the individual File objects.</p>
  
  <p>Is there a way to achieve that that <code>Content-length</code> headers are set for every part from the <code>FormData</code> object when sending the request?</p>
  
  <p>Below is the code I use, including my work-around to the problem. It actually uses <code>angular-js</code> to send the request, but I think this is not relevant to the question.</p>
  
  <pre><code>var form = new window.FormData();
  
  form.append('additional-field-1', new Blob(['some plain text'], {type : 'text/plain'}));
  
  for (var file in fileList) {
      var fileObj = fileList[file];
      var count = 1 + parseInt(file, null);
      form.append('file-size-' + count, new Blob([fileObj.size], {type : 'text/plain'}));
      form.append('file-' + count, fileObj);
  }
  
  $http.post(url, form, {
      transformRequest: angular.identity,
      headers: {'Content-Type': undefined}
  }).success(.....
  </code></pre>