How to Generate Multipart/Form-Data in Boomi Using Message Shape and Groovy Script

 Modern businesses frequently exchange files between applications, APIs and enterprise systems. Whether the requirement involves uploading PDFs, spreadsheets, images or multiple documents, APIs need a reliable way to transfer different types of data within a single request.

In Boomi integration services, Multipart/Form-Data is a useful approach for handling file-based API communication. Boomi provides multiple ways to construct multipart payloads, including the Message Shape and Groovy scripting within a Data Process Shape.

Understanding Multipart/Form-Data

Multipart/Form-Data is an HTTP encoding format commonly used to transfer files and additional form fields through POST requests. It separates individual data elements using a unique boundary string.

A typical multipart request contains:

  • Content-Type: Identifies the request format as multipart/form-data.

  • Boundary: Separates individual sections of the request body.

  • Content-Disposition: Specifies the form field name and file name.

  • Content-Type of each part: Identifies the format of the individual file or data element.

  • Closing Boundary: Indicates the end of the multipart payload.

This structure allows applications to send multiple files and different data types within one HTTP request.

Creating Multipart/Form-Data in Boomi

There are two practical approaches to generating multipart payloads in Boomi:

1. Using the Boomi Message Shape

The Message Shape can construct a multipart request by combining the boundary, headers, file content and closing delimiter.

A typical process involves:

  1. Receiving file details through API request headers.

  2. Using Set Properties to configure the file name and directory path.

  3. Retrieving the required file through a Disk Connector.

  4. Constructing the multipart payload using the Message Shape.

  5. Returning the generated document through a Return Documents step.

This approach is suitable for straightforward scenarios where the file structure and content length are known in advance.

However, it can introduce challenges when handling files of different sizes and formats. Static content-length values may require manual updates, while complex multipart structures can become difficult to maintain.

2. Using Groovy Script in the Data Process Shape

For more dynamic file-handling requirements, a Groovy Script within the Data Process Shape provides another approach.

The process can retrieve multiple files, identify their extensions, determine MIME types and construct the multipart payload programmatically.

A typical implementation includes:

  1. Capturing file names from incoming API headers.

  2. Splitting the input payload when multiple file names are provided.

  3. Setting file names and directory properties.

  4. Retrieving the files using a Disk Connector.

  5. Using Groovy 2.4 to generate multipart sections dynamically.

  6. Calculating the payload length.

  7. Adding the closing boundary and returning the output.

The script can determine common MIME types, including PDF, JSON, XML, CSV, DOCX, XLSX, PPTX, JPEG and PNG.

It also calculates the payload length based on the generated content rather than relying on a manually maintained value.

Important implementation consideration: Binary file content should be handled carefully. Converting arbitrary binary data into strings using ISO-8859-1 is a workaround that requires byte-preserving handling. For production implementations, a byte-oriented multipart construction approach is preferable. The generated payload should also use a unique boundary and correct HTTP headers.

Message Shape vs. Groovy Script: Which Approach Should You Choose?

Comparison

Message Shape

Groovy Script

Configuration

Template-based

Programmatic

Content length

May require manual configuration

Can be calculated dynamically

Multiple file formats

More complex to maintain

Can determine MIME types dynamically

Flexibility

Suitable for simpler structures

Better for complex requirements

Maintenance

Easier for basic payloads

Requires scripting knowledge

The right approach depends on file size, payload complexity, integration requirements and maintainability.

Conclusion

Generating Multipart/Form-Data in Boomi can be achieved using both the Message Shape and Groovy scripting. While the Message Shape is useful for straightforward scenarios, Groovy scripting offers greater flexibility when dealing with multiple files, different formats and dynamically generated payloads.

Choosing the right implementation can help create more adaptable API integrations and improve file exchange between enterprise applications.

Looking to simplify complex API and file-based integrations? As a Boomi Partner, TGH Software Solutions delivers expert Boomi Integration Services to help businesses connect applications, streamline data exchange and build scalable enterprise integration solutions that support evolving business needs.



Comments

Popular posts from this blog

Top 5 Emerging Tech Trends Businesses Can’t Ignore In 2025

Getting MDH Models from Boomi using Platform APIs

TGH Software Solutions: Your Preferred Boomi Implementation Partner