title: Adding attachments to mule message
body: <p>We are kind of stuck and do not know how to send attachments in mule message. We have some code in place that adds outbound attachments, but the values for Content-Disposition and Content-Type are autogenerated by mule and are not matching what is expected on the server. I have pasted the message that we are generating, the message that is expected (note the differences on content-types and content-dispositions). </p>
  
  <p>The content-disposition has to be “inline” on payload and “attachment” on the part of data-file.xml, but instead mule generates Content-Disposition: form-data; name="payload" and Content-Disposition: form-data; name="data-file.xml"
  This is the code snippet we are using to generate attachments:</p>
  
  <p>ByteArrayDataSource ds = new org.mule.message.ds.ByteArrayDataSource((byte[])docInput.getDataSet(),ATTACHMENT_FILE_NAME,"application/pdf");
  DataHandler dh = new javax.activation.DataHandler(ds);
  msg.addOutboundAttachment(ATTACHMENT_FILE_NAME, dh);</p>
  
  <p>Generated-Message-By_mule</p>
  
  <pre><code>POST /Operations/GenerateDocument HTTP/1.1
  X-MULE_ENDPOINT: http://bxl-rs-d1-vm:42420/Operations/GenerateDocument
  X-MULE_CORRELATION_SEQUENCE: -1
  X-MULE_ENCODING: UTF-8
  X-MULE_ROOT_MESSAGE_ID: be11dc40-a0af-11e4-89da-080027001cc8
  Client-Authorization: YyoAjWLrpsySg7Euxf9zs3S/ujAPjFuRkT7di6/Dk9o=
  Content-Type: multipart/mixed; boundary=" WeqbofBr94jK6QxpiWP36xMWse3bxwG21uQZed6”
  Date: Tue, 20 Jan 2015 14:22:20 GMT
  X-MULE_CORRELATION_GROUP_SIZE: -1
  Accept: application/xml
  X-MULE_SESSION: rO0ABXNyACNvcmcubXVsZS5zZXNzaW9uLkRlZmF1bHRNdWxlU2Vzc2lvbi7rdtEW7GGKAwAFWgAFdmFsaWRMAA1mbG93Q29uc3RydWN0dAAmTG9yZy9tdWxlL2FwaS9jb25zdHJ1Y3QvRmxvd0NvbnN0cnVjdDtMAAJpZHQAEkxqYXZhL2xhbmcvU3RyaW5nO0wACnByb3BlcnRpZXN0AA9MamF2YS91dGlsL01hcDtMAA9zZWN1cml0eUNvbnRleHR0ACdMb3JnL211bGUvYXBpL3NlY3VyaXR5L1NlY3VyaXR5Q29udGV4dDt4cAFwdAAkYmUxMjc4ODAtYTBhZi0xMWU0LTg5ZGEtMDgwMDI3MDAxY2M4c3IAJWphdmEudXRpbC5Db2xsZWN0aW9ucyRTeW5jaHJvbml6ZWRNYXAbc/kJS0s5ewMAAkwAAW1xAH4AA0wABW11dGV4dAASTGphdmEvbGFuZy9PYmplY3Q7eHBzcgAkb3JnLm11bGUudXRpbC5DYXNlSW5zZW5zaXRpdmVIYXNoTWFwndHZ72dFzgADAAB4cHcMP0AAAAAAABAAAAABdAAMT3BlcmF0aW9uVmFydAAQZ2VuZXJhdGVEb2N1bWVudHhxAH4ACXhweA==
  User-Agent: Jakarta Commons-HttpClient/3.1
  Host: bxl-rs-d1-vm:42420
  Content-Length: 16645
  
  --WeqbofBr94jK6QxpiWP36xMWse3bxwG21uQZed6
  Content-Disposition: form-data; name="payload"
  Content-Type: application/octet-stream; charset=ISO-8859-1
  Content-Transfer-Encoding: binary
  
  &lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;&lt;ns12:GenerateDocumentRequest xmlns:ns2="http://www.sodexo.com/CRM-Integration-Push" xmlns:ns3="http://www.sodexo.com/CRM-Integration-Update" xmlns:ns4="http://www.sodexo.com/CRM-Integration-PushFeedback" xmlns:ns5="http://www.sodexo.be/schemas/organization-api/1.0" xmlns:ns6="http://www.sodexo.be/schemas/organization-api/Phoenix-Organization-Update" xmlns:ns7="http://www.sodexo.com/CRM-Integration-UpdateFeedback" xmlns:ns8="http://www.sodexo.com/CRM-Address-Management" xmlns:ns9="http://net.sxpbelux.eurodb.services/eurodbServiceSchema-addressRequest" xmlns:ns10="http://net.sxpbelux.eurodb.services/eurodbServiceSchema-resultType" xmlns:ns11="http://www.sodexo.com/CRM-Document-Management" xmlns:ns12="http://schemas.datacontract.org/2004/07/Compro.Services.Contracts.DataContracts" xmlns:ns13="http://schemas.datacontract.org/2004/07/System" xmlns:ns14="http://net.sxpbelux.eurodb.services/eurodbServiceSchema-addressSearchRequest" xmlns:ns15="http://www.sodexo.com/CRM-Integration-Base" xmlns:ns16="http://www.sodexo.be/schemas/organization-api/Phoenix-OrganizationServices-Base" xmlns:ns17="http://www.sodexo.be/schemas/organization-api/Phoenix-Organization-UpdateFeedback" xmlns:ns18="http://net.sxpbelux.eurodb.services/eurodbServiceSchema-searchAddressResultType"&gt;&lt;ns12:AttachmentFiles xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/&gt;&lt;ns12:BusinessContext&gt;ServiceVoucher&lt;/ns12:BusinessContext&gt;&lt;ns12:BusinessReference&gt;Work_Voucher_Assigned&lt;/ns12:BusinessReference&gt;&lt;ns12:CommunicationKey&gt;CommunicationKey&lt;/ns12:CommunicationKey&gt;&lt;ns12:DataFile&gt;data-file.xml&lt;/ns12:DataFile&gt;&lt;ns12:FileFormat&gt;DOCX&lt;/ns12:FileFormat&gt;&lt;/ns12:GenerateDocumentRequest&gt;
  --WeqbofBr94jK6QxpiWP36xMWse3bxwG21uQZed6
  Content-Disposition: form-data; name="data-file.xml"
  Content-Type: text/plain; charset=US-ASCII
  Content-Transfer-Encoding: 8bit
  
  &lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
  &lt;ns2:DocumentData xmlns:ns2="http://www.sodexo.com/CRM-Integration-Template"&gt;
      &lt;Contacts&gt;
          &lt;Contact&gt;
              &lt;email&gt;email@abc.com&lt;/email&gt;
              &lt;firstName&gt;firstName&lt;/firstName&gt; ....
  </code></pre>
  
  <p>Message_expected_by_server</p>
  
  <pre><code>POST http://besvc-hq1000057:42420/Operations/GenerateDocumentWithAttachment/ HTTP/1.1
  Date: Wed, 26 Nov 2014 13:31:24 GMT
  Accept: application/xml
  X-Compro-Username: ASI
  Client-Authorization: S/rumqB+P0jfzY54eSeAGrKeMCfy7RYizno5A8D0ulI=
  Content-Type: multipart/mixed; boundary="d1261136-19f2-463e-ac7e-e8925c807c7d"
  Host: besvc-hq1000057:42420
  Content-Length: 26128
  Expect: 100-continue
  Connection: Keep-Alive
  --d1261136-19f2-463e-ac7e-e8925c807c7d
  Content-Type: application/xml; charset=utf-8
  Content-Disposition: inline
  [... some xml data ...]
  --d1261136-19f2-463e-ac7e-e8925c807c7d
  Content-Type: application/xml; charset=utf-8
  Content-Disposition: attachment; filename=order_created_badcom_data.xml
  [... some xml content ...]
  --d1261136-19f2-463e-ac7e-e8925c807c7d
  Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document
  Content-Disposition: attachment; filename=a.docx
  [... some binary content ...]
  --d1261136-19f2-463e-ac7e-e8925c807c7d
  Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document
  Content-Disposition: attachment; filename=a2.docx
  [... some binary content ...]
  --d1261136-19f2-463e-ac7e-e8925c807c7d--
  </code></pre>
  
  <p>If you have any ideas on how to get this to work, kindly let us know.</p>
  
  <p>Thanks and regards,
  Priya</p>