Skip to main content

Multipart content

Understanding how multipart content works

Transactional documents in Proactis usually contain attachments. By default those attachments will be sent along with the generated XML. Usually these attachments are PDF files but any file uploaded with a transactional document will be exported.

What is multipart content?

A multipart content HTTP request is a type of HTTP request that allows you to send multiple types of data, such as files, in a single HTTP request. Proactis uses multipart requests when transactional documents are pushed to the customers application.

A multipart content HTTP request consists of multiple parts, each containing a distinct piece of data. Each part includes a set of headers similar to those in a standard HTTP request, indicating the content type, content length, and other relevant information. The parts are separated by a boundary string that's specified in the request headers and is used to distinguish between the parts.

Here's a simplified example of what the structure of a multipart request might look like:

POST /upload HTTP/1.1
Host: example.com
Content-Type: multipart/mixed; boundary=boundary_string

--boundary_string
Content-Type: text/xml
Content-Disposition: form-data; name="INV100000002_CONCEPT_09_05_02.xml"
Content-Length: 10570

<XML>this is a XML document</XML>

--boundary_string
Content-Type: application/pdf
Content-ID: <invoicescan.pdf>
Content-Disposition: attachment; filename="invoicescan.pdf"
Content-Length: 60784

...binary...

--boundary_string--

In this example, the request includes a XML-document and a PDF file named invoicescan.pdf. The parts of the request are separated by the boundary string boundary_string, which is specified in the Content-Type header.

Processing multipart content

Processing multipart requests on the receiving end involves parsing the incoming HTTP request, extracting the different parts of data, and then handling each part appropriately. The steps generally include:

  1. Parsing Headers

    The receiving application first parses the initial headers of the HTTP request, including the Content-Type header. In the case of a multipart request, the Content-Type header will specify the multipart/mixed type along with the boundary string that separates the different parts.

  2. Identifying Boundaries

    The application extracts the boundary string from the Content-Type header. This boundary string is crucial for identifying the beginning and end of each part in the request.

  3. Splitting Parts

    The application splits the raw HTTP request content using the boundary string. This splits the request content into individual parts, each containing headers and the associated data.

  4. Parsing Parts

    For each part, the application parses the headers and content. Headers, such as Content-Type, might be used to determine the type of data being sent.

  5. Handling Data

    Depending on the content of each part, the application performs specific actions.

Different programming languages and web frameworks provide libraries or built-in functionalities to simplify the process of handling multipart requests.