title: How can I attach name-value pairs to a MultiPart POST request?
body: <p>This example works great for one or the other, but not both:</p>
  
  <pre><code>public void postData() {  
      //http://www.softwarepassion.com/android-series-get-post-and-multipart-post-requests/
      File f = new File(filename);
      try {
               HttpClient client = new DefaultHttpClient();  
               String postURL = "http://url.com/script.php";
  
  
               HttpPost post = new HttpPost(postURL); 
      //         List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(2);  
        //       nameValuePairs.add(new BasicNameValuePair("project", projectName));  
          //     nameValuePairs.add(new BasicNameValuePair("name", imageName));  
            //   post.setEntity(new UrlEncodedFormEntity(nameValuePairs));  
  
               FileBody bin = new FileBody(f);
               MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);  
               reqEntity.addPart("file", bin);
  
               post.setEntity(reqEntity); 
  
               HttpResponse response = client.execute(post);  
               HttpEntity resEntity = response.getEntity();  
               if (resEntity != null) {    
                         Log.i("RESPONSE",EntityUtils.toString(resEntity));
                   }
      } catch (Exception e) {
          e.printStackTrace();
      }
  
  
  }
  </code></pre>
  
  <p>It seems as if when I call <code>setEntity()</code>, the previous entity is overwritten -- so I can either have name value pairs, or file data, but not both. Do you know how to integrate them so I can use URL parameters in my upload? Simply appending them to the POST URL does not work.</p>
  
  <p>I also tried </p>
  
  <pre><code>  post.addHeader("project", projectName);
    post.addHeader("name", imageName);                 
  </code></pre>
  
  <p>but that didn't seem to work either.</p>
  
  <p>Thanks.</p>