Convert base64 file content from json field to physical file
V
Vincent CHEVALLIER
started a topic
3 days ago
Hello, I am reading a JSON file that contains information which I then save into a database. One piece of this information is a string representing the content of a file, encoded in Base64.
I would like to convert this Base64 content back into a file on my computer, but I haven't been able to figure out how to do it!
Best Answer
H
Harshit Upadhayay
said
1 day ago
Hello,
The documented approach is a scripting action in a process, using Java’s built-in Base64 decoder.
Add a Java Native Scripting action with Scripting Language set to groovy. Put the script in the action’s expression editor, without the %e(...)% wrapper.
Get the Base64 string into the script. For one file per row, link a bind link from your query to the action and read the column with __ctx__.getSourceResultSet().getString("<column>"). For a single file, store the string in a session variable and read it with __ctx__.getVariableValue("<path>").
Things to check if the file is missing or corrupted:
The file is written on the machine running the runtime. With Designer’s local runtime that is your computer; with a remote runtime it is the server. The folder must exist and be writable.
If the value starts with data:...;base64,, strip that prefix first.
For URL-safe Base64 (- and _), use Base64.getUrlDecoder().
The documented approach is a scripting action in a process, using Java’s built-in Base64 decoder.
Add a Java Native Scripting action with Scripting Language set to groovy. Put the script in the action’s expression editor, without the %e(...)% wrapper.
Get the Base64 string into the script. For one file per row, link a bind link from your query to the action and read the column with __ctx__.getSourceResultSet().getString("<column>"). For a single file, store the string in a session variable and read it with __ctx__.getVariableValue("<path>").
Things to check if the file is missing or corrupted:
The file is written on the machine running the runtime. With Designer’s local runtime that is your computer; with a remote runtime it is the server. The folder must exist and be writable.
If the value starts with data:...;base64,, strip that prefix first.
For URL-safe Base64 (- and _), use Base64.getUrlDecoder().
Vincent CHEVALLIER
Hello, I am reading a JSON file that contains information which I then save into a database. One piece of this information is a string representing the content of a file, encoded in Base64.
I would like to convert this Base64 content back into a file on my computer, but I haven't been able to figure out how to do it!
Hello,
The documented approach is a scripting action in a process, using Java’s built-in Base64 decoder.
groovy. Put the script in the action’s expression editor, without the%e(...)%wrapper.__ctx__.getSourceResultSet().getString("<column>"). For a single file, store the string in a session variable and read it with__ctx__.getVariableValue("<path>").Things to check if the file is missing or corrupted:
data:...;base64,, strip that prefix first.-and_), useBase64.getUrlDecoder().Docs: Scripting in processes, Scripting context, Java Native Scripting action.
Thank you
Harshit Upadhayay
Hello,
The documented approach is a scripting action in a process, using Java’s built-in Base64 decoder.
groovy. Put the script in the action’s expression editor, without the%e(...)%wrapper.__ctx__.getSourceResultSet().getString("<column>"). For a single file, store the string in a session variable and read it with__ctx__.getVariableValue("<path>").Things to check if the file is missing or corrupted:
data:...;base64,, strip that prefix first.-and_), useBase64.getUrlDecoder().Docs: Scripting in processes, Scripting context, Java Native Scripting action.
Thank you
-
File external resolver with encrypted value
-
Timeout on Mapping/Webservice call
-
UNIQUE TEMP TABLE NAMES
-
Previous step name from a sub-process of execute delivery
-
Dropping multiple tables at once in XDI
-
Freeze Designer and corrupted workspace
-
FileWait/Move/Copy: FileInclude with space
-
Change SVN user in the Designer
-
How to Specify the JVM used by the Designer?
-
Sybase IQ error: "Transaction %Id1% attempted to access %tableName% created by transaction %Id2%"
See all 73 topics