Page 1 of 1

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

Posted: Thu Sep 26, 2019 6:43 pm
by DEVP
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

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

Posted: Fri Sep 27, 2019 1:26 am
by LANSAGuru
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.

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

Posted: Tue Oct 01, 2019 11:54 pm
by DEVP
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.

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

Posted: Wed Oct 02, 2019 12:45 am
by LANSAGuru
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.

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

Posted: Wed Oct 02, 2019 10:16 am
by BrendanB
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).

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

Posted: Thu Oct 03, 2019 8:34 pm
by DEVP
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?