title: how to set Content-disposition header as attachment for file part?
body: <p>I am using the Python requests module to send a multi-part HTTP POST request that contains both form-data and a file attachment. </p>
  
  <p>The "Content-disposition" header for each multi-part object is set to "form-data", including the file part. </p>
  
  <p>I need the "Content-disposition" header for the form-data parts to still say "form-data", but the "Content-disposition" header for the file part must say "attachment" and not "form-data".</p>
  
  <p>How do I change the content-disposition header for the file-part only?</p>
  
  <p>My code:</p>
  
  <pre class="lang-py prettyprint-override"><code>#Python 3.7.3 (default, Apr 24 2019, 13:20:13) [MSC v.1915 32 bit (Intel)]
  import requests
  
  #USER PARAMETERS
  user_name = 'user_account'
  password = 'user_password'
  token = '45Hf4xGhj'
  
  #REQUESTS PARAMETERS
  url = '192.168.0.2'
  headers = {'content-type': 'multi-part/form-data'}
  data = {'Username':user_name, 'Password':password, 'Token':token}
  files = {'settings': ('settings.xml', open('settings.xml', 'rb'), 'app/xml')}
  
  #POST
  response = requests.post(url, headers=headers, data=data, files=files)
  </code></pre>
  
  <p>This is what the file-part's header looks like with Python requests:</p>
  
  <pre class="lang-html prettyprint-override"><code>Content-Type: app/xml
  Content-Disposition: form-data; name="settings"; filename="settings.xml"
  </code></pre>
  
  <p>and this is what I need the header of the file-part to look like:</p>
  
  <pre class="lang-html prettyprint-override"><code>Content-Type: app/xml
  Content-Disposition: attachment; name="settings"; filename="settings.xml"
  </code></pre>
  
  <p>I also tried to change the header by adding a header parameter to the file:</p>
  
  <pre class="lang-py prettyprint-override"><code>files = {'settings': ('settings.xml', open('settings.xml', 'rb'),
           'app/xml', {'Content-Disposition':'attachment'})}
  </code></pre>
  
  <p>but that had no effect. I can specify any other custom header and it will add it, but it does not change the "Content-Disposition" header if I use the approach.</p>
  
  <p>Any ideas? </p>
  
  <hr>
  
  <p>Using the toolbelt: </p>
  
  <pre><code>m = MultipartEncoder( fields={'Username': user_name, 
                                'Password': password, 
                                'Token': token, 
                      'settings': ('settings', open('settings.xml', 'rb'), 
                                   'app/xml', 
                                  {'Content-Disposition':'attachment'}
                                  )
                               } 
                      ) 
  
  r = requests.post('http://httpbin.org/post', 
                     data=m, 
                     headers={'Content-Type': m.content_type}) 
  </code></pre>
  
  <blockquote>
    <p>results in </p>
  
  <pre><code>...--2ba9624051854b6d961bad262a1792fc 
  Content-Disposition: form-data; name="settings"; filename="settings"
  Content-Type: app/xml 
  &lt;?xml version="1.0" encoding="utf-16"?&gt;...
  </code></pre>
  </blockquote>