Home > Forum > Tips&Tricks > "Export/transfer" BAse64 picture field content as attachment

"Export/transfer" BAse64 picture field content as attachment
0

Hi everybody,

has anybody an idea how I could manage to make (copy) out of a base64 type picture field an attachment for a bunch of instances? I.e. I have an QR code within my workflow instance as picture field. But I need to export it for external use.

Kind regards
Klaus

MVP

HI Klaus,

according this post you could convert the base64 encoding to binary using SQL:

https://stackoverflow.com/questions/25897140/converting-from-base64-string-to-varbinarymax-in-sql-server
SELECT
Id,
AttachmentBase64, --the base64 value we want converted to varbinary
CAST(AttachmentBase64 AS xml).value('xs:base64Binary(.)', 'varbinary(max)') AS AttachmentBinary
FROM Attachments

In combination with the "special" feature of the add attachment action, you could add the picture as an attachment in the same instance.
SELECT convert(image,'0x') AS Content, 'file1.txt' AS FileName
https://docs.webcon.com/docs/2023R3/Studio/Action/Attachments/Action_AddAttachment


If you need to copy it to another attachment, I would opt for the API approach:

https://daniels-notes.de/posts/2023/copy-attachment-to-other-workflow

Best regards,
Daniel

MVP
In reply to: Klaus Seidler

Hi Daniel,

thanks a lot for the quick reply!

That looks rather easy (I have to admit I'm still working on understanding it) ;-)

Would it be possible to store the files (if I run directly from the SQL Management Studio) to a file share e.g. C:\Temp\ ?

Kind regards,
Klaus

Hi Klaus,

if you want to store them on a hard drive, you could use a PowerShell action.

https://docs.webcon.com/docs/2023R3/Studio/Action/Integration/Action_PSExecutor#3-powershell-script


You have two options here:
1. Pass the base64 value as a variable and convert it a file

2. Pass the instance id and access the database directly
When I'm using a PowerShell action I'm creating it externally and like to pass the whole script into the action. This includes the variable values I use for testing.
Storing a base64 value in an action did work but caused long waiting times opening/storing the action. Therefore, it may be an option to directly access the database depending on your situation.
Im using the AutoSaveIntervall to verify whether the script is executed from the ISE:
https://daniels-notes.de/posts/2021/deploying-assemblies#script-development

You can take over a large part of this script for the first option.
https://github.com/Daniel-Krueger/webcon_artifactDeployment/blob/main/2021.1.3.205/RemoteDeployment_fromBPS.ps1

Best regards,
Daniel