KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Decoding base64 picture stored in a blob
PRODUCT: 4D | VERSION: 2003.2 | PLATFORM: Mac & Win
Published On: April 15, 2004

If you have a picture encoded as base64 and stored in a blob and want to be able to view it, you need to decode it. The easiest way to accomplish this is to use the 4D Internet Command--IT_Decode. Find more information regarding the IT_Decode command.

When you use the IT_Decode command it will create a new decoded copy of the original base64 encoded blob file/variable/etc and place the new decode copy in the specified directory. If no directory is specified, the new decoded copy will be created and placed next to the database structure. If you do not need the picture file to be stored on your hard drive; you can use the DOCUMENT TO BLOB to pull in the picture, store the picture in a variable, and delete the picture file. Below are example codes:

C_LONGINT($index)
C_BLOB($1;$bTemp)
C_PICTURE($0;$Pic)

BLOB TO DOCUMENT("bPic1.txt";$1)
$index:=IT_Decode ("bPic1.txt";"temp.txt";2)

DOCUMENT TO BLOB("temp.txt";$bTemp)
BLOB TO PICTURE($bTemp;$Pic)

DELETE DOCUMENT("bPic1.txt")
DELETE DOCUMENT("temp.txt")

$0:=$Pic