Our business has an old database table which stores/contains files using VARBINARY(MAX) as the datatype. It is my understanding that this datatype is not supported in K2 Five and thus I cannot create a SmartObject on this table and display these files using a SmartForm.
The goal is to somehow migrate these files out of the current database table, and upload them into a different table in the format that K2 recognizes. Which, from a DB perspective using VARCHAR(MAX) as the datatype, looks something like this -
My question is….what is the best approach to achieve this objective? Can .NET code we written to somehow cycle through these old DB records/files and upload them into our existing table via a K2 API? Or even call the existing table’s own SmartObject from .NET code in order to upload the files?
Best answer by boringNerd
As you have pointed out, K2 stores the files into the database in the following format:
So you provide the name of the file in <name></name>, but the value inside <content></content> is going to be a little tricky. This value is actually a Base64-encoded value of your entire file.
Just to show you how this work, you can paste this Base64 values into this tool and retrieve the actual file:
I got this Base64 value by encoding a simple file using this converter.
You can definitely write a simple .NET or C# application to do this. You just need to loop through your database, download the file, grab the name of the file, Base64-encode the file, piece together the different parts into a string that resembles the above, and store it into the new database.