Convert files to base64

<< Click to Display Table of Contents >>

Navigation:  Low-code Process Automation > Studio Cloud - Authoring environment > Bizagi Studio > Process wizard > Business Rules > Business Rules examples > Documents and files > File management with expressions >

Convert files to base64

Overview

Bizagi offers a function to transform your files to base64. You might need this transformation when using services that handle file data or while using Bizagi's SOA layer.

 

To transform your data just use the following function, this will return a String with your data on base64:

 

CHelper.ToBase64(data)

 

The following attributes are needed:

data: Your file data.

 

Example

In the following sample process, assume we have a process entity called OfficeSupplyRequest.

Such process uses the following data model:

 

ProductRequestDataModel

 

All the documents received are rounded up in the Request Summary attribute. This information must be sent to another system. To do so, we will transform this file to base64 and send the string as a web service input parameter, were then it will be decoded on the other system. Keep in mind that only one summary is allowed per case.

 

We are going to store the base64 data on the variable SummaryBase64 that we will later use as an input parameter for the service.

 

The expression would be as follows:

 

tobase64_01

 

var summary = CHelper.GetValueAsCollection(<OfficeSupplyRequest.RequestSummary>);

var summaryData= summary.get(0).getXPath("Data");

SummaryBase64 = CHelper.ToBase64(summaryData);

 

The expression above obtains the array of files stored in the RequestSummary file-type attribute. Then it navigates through the array and obtains the data of the file to be transformed. Finally the data is converted to base64 and stored in the SummaryBase64 variable.


Last Updated 1/6/2022 4:17:35 PM