How to convert a pdf to base64 to use in the XMLWriterService

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
KoenDP
Posts: 3
Joined: Tue Jun 29, 2021 4:43 pm

How to convert a pdf to base64 to use in the XMLWriterService

Post by KoenDP » Fri Oct 15, 2021 1:48 am

I have a pdf that that must be converted in to base64 so it can be mapped into an xml element with the XMLWriterService.

From the Lansa Integrator documentation i understand it can be done by the HashService:
5.8.3 HASH
The HASH command generates the hash of the specified field or file. The hash value is returned in the command message response field


I tried this in integrator with :

HASH FILE(/tmp/NL00000007.PDF) HASHENCODING(*BASE64)

Although the message response field is long enough it contains only 28 characters.

It is not clear to me what parameters are to be used or if this is even the right way to do this.
Any suggestions?

caseywhite
Posts: 142
Joined: Thu May 26, 2016 1:17 am

Re: How to convert a pdf to base64 to use in the XMLWriterService

Post by caseywhite » Fri Oct 15, 2021 2:50 am

If you are going to use LANSA Integrator I would suggest using the XMLBindFileService. It is newer and you can use the visual mapping of XML from Integrator studio. Either way though I think both services should automatically convert a BLOB data type to Base64 for you so you don't need to use the HASH service.

If your PDF is stored in the IFS just do the following where field UPLFIL is defined as a BLOB data type. That field doesn't need to be in a file.
#UPLFIL := #SA_DIR + '/' + #SA_FILNAM

You would send the field #UPLFIL. In the case of the XMLBindFileService it should just convert the BLOB data to Base64. I haven't used the XML Writer in a very long time so can't confirm how it would work but I suspect it would do the same thing.

KoenDP
Posts: 3
Joined: Tue Jun 29, 2021 4:43 pm

Re: How to convert a pdf to base64 to use in the XMLWriterService

Post by KoenDP » Fri Dec 03, 2021 2:11 am

Indeed works as you suggest with XMLBindFileService.

Thanks :D

Post Reply