}
// Set the multipart for the post
int partNo = partlist.size();
Part[] parts = (Part[])partlist.toArray(new Part[partNo]);
MultipartRequestEntity multiPart = new MultipartRequestEntity(parts, post.getParams());
post.setRequestEntity(multiPart);
// Set the content type
String multiPartContentType = multiPart.getContentType();
post.setRequestHeader(HEADER_CONTENT_TYPE, multiPartContentType);
// If the Multipart is repeatable, we can send it first to
// our own stream, without the actual file content, so we can return it
if(multiPart.isRepeatable()) {
// For all the file multiparts, we must tell it to not include
// the actual file content
for(int i = 0; i < partNo; i++) {
if(parts[i] instanceof ViewableFilePart) {
((ViewableFilePart) parts[i]).setHideFileData(true); // .sendMultipartWithoutFileContent(bos);
}
}
// Write the request to our own stream
ByteArrayOutputStream bos = new ByteArrayOutputStream();
multiPart.writeRequest(bos);
bos.flush();
// We get the posted bytes using the encoding used to create it
postedBody.append(new String(bos.toByteArray(),
contentEncoding == null ? "US-ASCII" // $NON-NLS-1$ this is the default used by HttpClient
: contentEncoding));