(C) Convert any File to Base64 (and back)
Demonstrates how to get the contents of any file as a base64 string, and then write it back.
#include <C_CkBinData.h>
void ChilkatSample(void)
{
HCkBinData bd;
BOOL success;
const char *b64Str;
HCkBinData bd2;
bd = CkBinData_Create();
// This example will load a PDF and return it as a base64 string.
success = CkBinData_LoadFile(bd,"qa_data/pdf/helloWorld.pdf");
if (success != TRUE) {
printf("Failed to load file.\n");
CkBinData_Dispose(bd);
return;
}
b64Str = CkBinData_getEncoded(bd,"base64");
printf("%s\n",b64Str);
// Now write the base64 string back to the binary PDF file:
bd2 = CkBinData_Create();
success = CkBinData_AppendEncoded(bd2,b64Str,"base64");
success = CkBinData_WriteFile(bd2,"qa_output/helloWorld.pdf");
CkBinData_Dispose(bd);
CkBinData_Dispose(bd2);
}
|