How do you decode a base64 string and turn it into a file (as pdf) and save it to a network drive

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
DEVP
Posts: 3
Joined: Mon Mar 26, 2018 11:29 pm

How do you decode a base64 string and turn it into a file (as pdf) and save it to a network drive

Post by DEVP » Thu Sep 26, 2019 6:43 pm

LANSA Integrator - How do you decode a base64 string and turn it into a file (as pdf) and save it to a network drive using a function?

I am working on a project using Royal Mail API Shipping V2 REST APIs.
One of the APIs sends a JSON response back containing an entity which is in BASE64 encoded PDF format ( postage label )which I am mapping to a BLOB field. All OK so far. It is the next stage that I am struggling with.
I would like to decode a base64 string (postage label as a BLOB) and turn it into a file (as pdf) and save it to a network drive.

Is this the way to decode base64 string ? ( #LABEL is the BLOB field )........

Define_Com Class(#XPRIM_Binary) Name(#HashBytes)
#HashBytes.FromBase64String String(#LABEL)

Thanks in advance for your answers.

Regards,
Devinder

LANSAGuru
Posts: 68
Joined: Thu Mar 24, 2016 5:31 am

Re: How do you decode a base64 string and turn it into a file (as pdf) and save it to a network drive

Post by LANSAGuru » Fri Sep 27, 2019 1:26 am

https://docs.lansa.com/14/en/lansa015/c ... 0_0020.htm

Define_Com Class(#XPRIM_Binary) Name(#HashBytes)
#HashBytes.FromBase64String String( #JsonObject.GetString('hash') )

In your case you need to get the BLOB into a string and then just execute the command above.
That is the bit that goes #JsonObject.GetString('hash') is the base64 encoded information you will need.

In this case the #JsonObject is a different #XPRIM object type which obviously returns a string from a base64 encoded hash...its just getting a string out of a json object, which is not relevant here...you already have the string but its in a blob. I think a simple assign should do it

#string := #blob .... possibly with a method on the blob to convert to string....

Then the .FromBase64String method does exactly what you want leaving the BLOB back in the #HashBytes variable.

DEVP
Posts: 3
Joined: Mon Mar 26, 2018 11:29 pm

Re: How do you decode a base64 string and turn it into a file (as pdf) and save it to a network drive

Post by DEVP » Tue Oct 01, 2019 11:54 pm

Thanks for your help.

The penny has dropped!

I believe I was over-complicating the issue - The bind service to read HTTP request content with the BLOB field receiving the 64bit encoded field element creates a object file with a .BIN extension. By reading the BLOB field will give you a path to the object on the IFS not the object itself.
This object with a .BIN extension file is the PDF object ( it is what it is) If I was to open that object with PDF reader it displays the PDF document.

Now I need to find a way to "move" this object to a network folder on a PC server.

LANSAGuru
Posts: 68
Joined: Thu Mar 24, 2016 5:31 am

Re: How do you decode a base64 string and turn it into a file (as pdf) and save it to a network drive

Post by LANSAGuru » Wed Oct 02, 2019 12:45 am

There are a couple of ways to do this.

#1 move via FTP

#2 mount a drive using QNTC

I think the following are all true, but would google (google IBMi and QNTC) this and verify with IBM

Same domain (IBMi must join the windows domain of the Wins Server
user/pwd must be synchronized with the profile doing the copy
iSeries sends pwd lowercase unless using PWDLVL = 2 (or higher)

Command to create the share name

mkdir /QNTC/{share name}
e.g.

/QNTC/myshare

#3 mount a driver using QFileSVr

This may only be with IBMi to IBMi boxes, can't remember exactly....Again google it to see the details from IBMi

======

I think #2 is most commonly used.

BrendanB
Posts: 35
Joined: Tue Nov 24, 2015 10:29 am

Re: How do you decode a base64 string and turn it into a file (as pdf) and save it to a network drive

Post by BrendanB » Wed Oct 02, 2019 10:16 am

you could also use the Integrator SMB Service to move the file from the IFS to a Network Server (SMB service handles domain users, so that might be easier than setting up FTP/QNTC).

DEVP
Posts: 3
Joined: Mon Mar 26, 2018 11:29 pm

Re: How do you decode a base64 string and turn it into a file (as pdf) and save it to a network drive

Post by DEVP » Thu Oct 03, 2019 8:34 pm

Integrator SMB appears to be the ideal solution - What are the steps involved in setting up and using SMB service? Do you need to install any third party software or is it all part of Integrator?

Post Reply