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
Base64 decode
Moderators: Jon, Steve, Ian, Dave
-
- Moderator
- Posts: 1342
- Joined: Wed Sep 12, 2007 12:49 pm
Ebase doesn't include any built-in functions to do this. You would need to use Java, something like this:
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.
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 );
0 x
-
- Ebase User
- Posts: 81
- Joined: Thu Jul 30, 2015 12:44 pm
Who is online
Users browsing this forum: No registered users and 5 guests