[Multipart/form-data] Demo

Forge Component
Published on 6 Sep by João Barata
5 votes
Published on 6 Sep by João Barata

Kindly show some demo, how it work. 

i am using Postman to test the API, its has one json   and binary file in body content. 


Hi Mohan,

I don't have a demo (because that would need a REST service that needs a multipart/form-data, and it's not easily possible to create it in OutSystems). However, these are the steps to take:

  1. Create a List of Part Structures, each Part containing the desired content. In your case, the JSON goes in the Content Attribute of one item, and the binary file goes in the ContentBinary Attribute of the other. Make sure to set the right Name, as required by the API you're connecting to.
  2. Call MultipartFormDataCreate, use the Part List as input. You can omit the Boundary Parameter, it will be created for you (though if you require a specific boundary, you can specify it of course).
  3. Call your API. Typically, you'll need to specify the Content-Type, for which you can use the ContentTypeGet Function. As input it needs the boundary, which is the BoundaryUsed Output Parameter of MultipartFormDataCreate. See below on how to subsequently use the ContentType.
  4. As content for your API Method, you specify the MessageBinary Output Parameter of MultipartFormDataCreate.

In order for your REST API to work properly, you will need to set the right Content-Type in the header. To do so, specify an Input Parameter ContentType, with its "Send In" Property set to "HeadeR" and its "Name in Request" Property set to "Content-Type":

The binary content should be sent in the body ("Send In" set to "Body"), and its data type should of course be "Binary Data".

If you need an example, you can take a look at my ValidSign Component, which uses Multipart/form-data as described above.