Skip to content

qie.getMultipartBuilder

Signature: qie.getMultipartBuilder(boundary*, mimeType*)

Returns: org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder multipartBuilder - the multipart content builder object

Returns an builder object that is used to correctly generate a multipart content for a web service connection.

Note

The builder object is required for calls to qie.addMultipartContentBinary() and qie.addMultipartContentText(). See example scripts for more information.

Parameters

Type Name Description Default
String boundary* (optional) the boundary to be used between content parts httpclient_boundary_{UUID}
String mimeType* (optional) the mimeType to use in the Content-Type form-data

Example

// Build multipart content for a web service request
// Step 1: Initialize the Multipart Builder
var multipartBuilder = qie.getMultipartBuilder(); // Use the default boundary and mimeType

// Step 2: Add a plain text part using default form-data Content-Disposition
multipartBuilder.addTextBody(
   "textPart",                                      // Part name
   "This is plain text content.",                   // Text content
   org.apache.hc.core5.http.ContentType.TEXT_PLAIN  // Content-Type
);

// Step 3: Add a binary file part using default form-data Content-Disposition
var fileData = qie.base64DecodeToBytes("aGVsbG8=");         // Load file as byte array */
multipartBuilder.addBinaryBody (
   "filePart",                                          // Part name
   fileData,                                            // File content as byte array (could also be a stream)
   org.apache.hc.core5.http.ContentType.IMAGE_PNG,      // Content-Type
   "aang.jpg"                                           // File name (optional)
);

// Step 4: Send the multipart entity
var value = qie.callRESTWebService(
     "Vendor API",
     "https://example.com/upload",
     "POST",
     multipartBuilder,
     null, // Use the Content-Type parameter only to specify additional optional attributes (e.g., type or version); the multipart/{mimeType}, and boundary are set automatically by the MultipartBuilder.
     qie.newParameterMap(),
     60000);