34
Views
13
Comments
Consume REST API with Multipart/form-data

Hi,

We are consuming REST API which contains File content(binary) in request.

{

  "user_name": "abg@gmail.com",

  "client_id": 2,

  "opportunity_id": "B55F-02353FD1CE57",

  "time_stamp":"2025-04-26 17:00:00",

  "file_name": "test1.csv",

  "file_content": <<binary data >>

}

Is it possible to add the file binary in our custom request structure or we need to create another input parameter for file binary with data type as RequestPart?

REST API Request Format we have kept as - Multipart/form-data

Best Regards,

Nitin

2023-08-18 10-40-36
Deepak M

Hi Nitin,

You will need to pass the file as a separate input parameter of type Binary Data with Send In = Request Part

You can’t include the binary directly in the JSON because multipart/form-data sends each field (including files) as separate parts. JSON can't handle raw binary properly in that format.

So, define all fields (user_name, .....) as Request Parts, and add one more for file_content as Binary Data. That should work.

Hope this helps.

2022-08-26 11-04-22
Nitin Chavan

Hi @Deepak - EONE ,

Thank you for quick reply! Do you mean input parameter should be List of RequestPart?

I need to provide User_name, Client_id ... in this RequestPart list ?

Could you please elaborate more.

Best Regards,

Nitin

2023-08-18 10-40-36
Deepak M


Yes, exactly. When you're calling an API with multipart/form-data, each form fields like user_name, client_id and etc, must be added as a separate item in the RequestParts list. 

So, if the API expects user_name, client_id, and a file, you should:

  • Add user_name as a Request Part (set PartText)

  • Add client_id as a Request Part (set PartText)

  • Add the file as a Binary Data input, with Send In = Request Part, and set the name, filename, and content type.

2019-01-07 16-04-16
Siya
 
MVP

@Nitin Chavan : Please have a look at the documentation provided at https://success.outsystems.com/documentation/11/integration_with_external_systems/rest/consume_rest_apis/payload_request_examples_when_consuming_a_single_rest_method/ . Refer to section "Multipart/form-data". Do copy the sample shown there and put in your code and make necessary changes - move your fields in respective boundary and test the code and it should work.

2025-08-07 06-30-56
Amit J
Champion

Yes, since you're using multipart/form-data as the request format in OutSystems and your request includes a binary file, you cannot include the file binary inside a custom structure as a regular field like "file_content": <>. Instead, you must define it as a separate input parameter using the RequestPart data type.

Recommended Approach in OutSystems

To send binary content via multipart/form-data, do the following in your consumed REST API method definition:

Define Input Parameters:

  • For all non-binary values (e.g., user_name, client_id, etc.), add input parameters of type Text/Integer.

  • For file_content, add:

    • Name: file_content

    • Data Type: Binary Data

    • Send In: Body

    • Type: Request Part



2022-08-26 11-04-22
Nitin Chavan

Thank you @Amit Jain !

So I need to specify two input parameters in request?

1. Custom structure

{

  "user_name": "abg@gmail.com",

  "client_id": 2,

  "opportunity_id": "B55F-02353FD1CE57",

  "time_stamp":"2025-04-26 17:00:00"

}

2. RequestPart for 1 file single object. If we have more than 1 file then List of RequestPart 

{  "Name": "",  "PartText": "",  "PartBinary": "string",  "Filename": "",  "ContentType": ""}

Also the API exposed should follow this same input structure?

Best Regards,

Nitin


2025-08-07 06-30-56
Amit J
Champion

No,
Can you check the both OML I have exposed api from one and consume from another with binary data.

https://amitj.outsystemscloud.com/App02/Screen1?_ts=638889819646430408



App01.oml
2025-08-07 06-30-56
Amit J
Champion

Another module 

Please install both and test by correcting the consumer api url, it will work

App02.oml
2022-08-26 11-04-22
Nitin Chavan

Thank you @Amit Jain for your help. I really appreciate your hard work.

In your example file is returned in response. 

We want to send file data in Request as input. If the request Format is JSON then file will be send as base64 string. But we want to send file as binary data.

Best Regards,

Nitin

2025-08-07 06-30-56
Amit J
Champion

Can you try to keep json instead of Multipart/form-data.
Can you check now again new changes in modules i am able to send the FIle  data as  base64


Also send file data as Base64 in the request body when consuming an API — and this is a common and valid approach, especially when working with REST APIs that expect JSON.

JSON limitation: JSON does not support binary directly — only text (including Base64).

Platform compatibility: Base64 works seamlessly across platforms (like browsers, mobile apps, OutSystems, etc.).

API support: Many APIs (especially in OutSystems) are designed to accept Base64 strings for files.

In OutSystems, when consuming a REST API: You can only send a Base64 string (not raw binary) in a text input parameter. If you're using Binary Data as input, it must still be Base64-encoded on the client or calling side. 


2025-08-07 06-30-56
Amit J
Champion

Can you try to keep json instead of Multipart/form-data.
Can you check now again new changes in modules i am able to send the FIle  data as  base64


Also send file data as Base64 in the request body when consuming an API — and this is a common and valid approach, especially when working with REST APIs that expect JSON.

JSON limitation: JSON does not support binary directly — only text (including Base64).

Platform compatibility: Base64 works seamlessly across platforms (like browsers, mobile apps, OutSystems, etc.).

API support: Many APIs (especially in OutSystems) are designed to accept Base64 strings for files.

In OutSystems, when consuming a REST API: You can only send a Base64 string (not raw binary) in a text input parameter. If you're using Binary Data as input, it must still be Base64-encoded on the client or calling side. 


App01.oml
2025-08-07 06-30-56
Amit J
Champion

Another OML 

App02.oml
2022-08-26 11-04-22
Nitin Chavan

Hi @Amit Jain ,

Thank you for your sample project!

We are able to transfer file using base64, but we are looking for future proof solution to send large file via REST API, so we looking for Multipart/form-data.

Best Regards,

Nitin

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.