Perspective Download base64 file

I have a system where I can use an api to get a backup as base64
I save this backup inside a mssql server
I then want to be able to download those backup with perspective

If I send the base64 data as plain text, I’m able to convert it using powershell to a working archive

I use binascii.a2b_base64 to convert to base64 string to bytes
When I check the size of the result, using “len”, I have the right number 773758, that is the expected file size, but the file I receive using the following is 1160274 bytes."backup.7z", binascii.a2b_base64(filecontent), "application/zip")

Am I missing some encoding or something?

I would use a Java function to convert the base64 to bytes; there’s a lot of layers of translation involved if you use a Jython method.
Try this snippet to get a byte[]:

1 Like

Any docs on available Java library/tools?

Well, for a start you’ve got the whole Java standard library (which does have the ability to decode Base64 as well, it’s just significantly less ergonomic to use):

Then you’ve got Ignition specific stuff:

Then you’ve got all the third party repos we bring in; depending on what scope you’re in this will be different, but you can take a look at the .ignition cache, or look in the gateway’s lib/ directory - you’ll find .jar names, which are usually pretty self explanatory/let you find your way back to a documentation page.

It’s effectively impossible to document it all, especially since it’s subject to change between versions; the system. scripting libraries are technically the only officially exposed way; but, for instance, that Base64 module in our common directory is so deeply tied to our code (and has been for years) that it’s pretty much perfectly safe to use.

1 Like