MimeMultipart parts = new MimeMultipart();
if (uploadContexts != null && !uploadContexts.isEmpty())
{
for (UploadContext uploadContext : uploadContexts)
{
InternetHeaders headers = new InternetHeaders();
headers.addHeader(FileUpload.CONTENT_TYPE, uploadContext.getMimeType());
List<NamedString> attributes = uploadContext.getMimeAttributes();
if (attributes != null && !attributes.isEmpty())
{
for (NamedString attribute : attributes)
{
headers.addHeader(attribute.getName(), attribute.getValue());
}
}
MimeBodyPart mimeBodyPart = new MimeBodyPart(headers, uploadContext.getUploadData());
parts.addBodyPart(mimeBodyPart);
}
}
final String paramContentDispositionHeader = FileUpload.FORM_DATA + "; name=\"";
if (formParams != null && !formParams.isEmpty())
{
Map<String, String[]> params = new HashMap<String, String[]>(formParams.size());
for (NamedString formParam : formParams)
{
InternetHeaders headers = new InternetHeaders();
headers.addHeader(FileUpload.CONTENT_DISPOSITION, paramContentDispositionHeader + formParam.getName() + "\"");
MimeBodyPart mimeBodyPart = new MimeBodyPart(headers, formParam.getValue().getBytes());
parts.addBodyPart(mimeBodyPart);