//Create a multi part builder
var multiPart = qie.getMultipartBuilder(qie.getUUID(true));
//Add parts to the multi part builder
qie.addMultipartContentText(multiPart, 'textPart1', 'content 1');
qie.addMultipartContentText(multiPart, 'textPart2', 'content 2');
qie.addMultipartContentText(multiPart, 'textPart3', 'content 3');
qie.addMultipartContentBinary(multiPart, 'binaryPart1', qie.readFile('somelocalpath/report.pdf'), 'application/pdf', 'report.pdf');
// now we will build the multiPart and get the httpEntity so that we can have the httpEntity provide the contentType for us
// NOTE: the httpEntity must be closed after use to prevent memory leaks
var httpEntity = multiPart.build();
try {
// call the ws-connection that is ready to receive this request
var parameterMap = qie.newParameterMap();
var urlTemplate = qie.evaluateTemplate(qie.getWsEndpointUrl("{ws-connection}"));
var value = qie.callRESTWebService(
"{ws-connection}",
urlTemplate,
"POST",
multiPart,
httpEntity.getContentType(), // Use the httpEntity to get the contentType
parameterMap,
60000);
} finally {
// close the httpEntity after use to prevent memory leaks
httpEntity.close();
}
//This code will debug out the boundaries if you need or want to see them.
var entity = multiPart.build();
var outputStream = new java.io.ByteArrayOutputStream();
entity.writeTo(outputStream);
var entityString = outputStream.toString("UTF-8");
qie.debug(entityString);