Base64 decode

Post any questions you have about using the Verj.io Studio, including client and server-side programming with Javascript or FPL, and integration with databases, web services etc.

Moderators: Jon, Steve, Ian, Dave

azaleas
Ebase User
Posts: 81
Joined: Thu Jul 30, 2015 12:44 pm

Base64 decode

#1

Postby azaleas » Tue Feb 09, 2016 10:28 am

I have a field with base64 decoded value (image) and I want to decode it on server side and then save the data as a file with ebase file service.

How can I decode this and write to a file? There're btoa and atob functions but I wanted to know if there's something ready available in Ebase and if not what would be the best practise with Ebase?

PHP has a built in base64_encode and base64_decode functions ready to use for this manipulation
0 x

Jon
Moderator
Moderator
Posts: 1342
Joined: Wed Sep 12, 2007 12:49 pm

#2

Postby Jon » Thu Feb 11, 2016 10:29 am

Ebase doesn't include any built-in functions to do this. You would need to use Java, something like this:

Code: Select all

var file = new java.ioFile( "C:/temp/myfile.jpg" );
var bytes = org.apache.commons.codec.binary.Base64.decodeBase64( "encodedString" );
org.apache.commons.io.FileUtils.writeByteArrayToFile( file, bytes );
This uses the apache commons codec library and the Ebase V5 distribution includes a rather old version of this (1.3). You would need to replace this (in tomcat/webapps/ebase/WEB-INF/lib) with the latest version to get this code to work. If you're using Ebase V4 you will need to add both the apache commons codec library and the apache commons io library.
0 x

azaleas
Ebase User
Posts: 81
Joined: Thu Jul 30, 2015 12:44 pm

#3

Postby azaleas » Thu Feb 11, 2016 12:10 pm

Thanks Jon, but I found a JS function which solved the issue.
0 x


Who is online

Users browsing this forum: No registered users and 12 guests