Question

Encode a .xlsx file into Base64

Hello,

I am working in a user story which I need to convert a Page List into a .xlsx file. After that, I need to send this file as a Base64 string inside a connector.

I separated this user story in 3 steps:

  1. Call MSOGenerateExcelFile to generate the .xlsx file. - Done
  2. Use Base64Encode() function to convert the .xlsx into a Base64 string. - Doing
  3. Call the integration.

I did the first step successfully, but I don't know how to do the second step.

I saw in the bellow link that I can use this function to convert a Binary File into a Base64:

https://community.pega.com/sites/default/files/help_v719/procomhelpmain.htm#definitions/b/base64.htm

So, I was thinking to create a Binary File from the .xlsx that I have and call the Base64Encode() function to do this whole process, but I cannot figure out how to convert my file into a Binary File inside Pega.

Can someone give me hints to do that or maybe suggest another approach to create the Base64 string?

Thank You.

Witon S. Tuji.

Correct Answer
December 27, 2018 - 2:24pm

Hello,

I wanted to post a solution that I figured out:

After generating the .xlsx file with the MSOGenerateExcelFile, I did a property-set to the pxRequestor.pyFileUpload property. The set value is the pxProcess.pxServiceExportPath (Pega path) + the file name (declared in the MSOGenerateExcelFile).

To finish, I called the function @uploadFile() in a property-set which populated string type property. This property will contain your Base64, File Extension, File Name and File Path.

This @uploadFile() function will look at the file path located in pxRequestor.pyFileUpload, thats why I needed to populate this property after the MSOGenerateExcelFile.

Hope it helps someone in the future.

Comments

Keep up to date on this post and subscribe to comments

December 27, 2018 - 2:24pm

Hello,

I wanted to post a solution that I figured out:

After generating the .xlsx file with the MSOGenerateExcelFile, I did a property-set to the pxRequestor.pyFileUpload property. The set value is the pxProcess.pxServiceExportPath (Pega path) + the file name (declared in the MSOGenerateExcelFile).

To finish, I called the function @uploadFile() in a property-set which populated string type property. This property will contain your Base64, File Extension, File Name and File Path.

This @uploadFile() function will look at the file path located in pxRequestor.pyFileUpload, thats why I needed to populate this property after the MSOGenerateExcelFile.

Hope it helps someone in the future.

December 27, 2018 - 3:34pm
Response to WiltonT6

Thank you for sharing your resolution with the community and marking your reply as the Correct Answer, @WiltonT6!

Marissa | Community Moderator | Pegasystems Inc.