Unicode C
Unicode C
Set a MIME Body from Binary Bytes (BinData)
See more MIME Examples
Demonstrates the Chilkat Mime.SetBodyBd method, which sets the decoded body bytes from a BinData, changes the transfer encoding to base64, and preserves the bytes exactly. The only argument is the BinData.
Note: The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.
Background: This is the direct way to put arbitrary binary content into a part from memory — a generated image, a decrypted blob — without a temporary file. Chilkat base64-encodes it so the bytes survive text-based transports unchanged. Note it does not set a
Content-Type or disposition, so assign those yourself to describe what the bytes are.Chilkat Unicode C Downloads
#include <C_CkBinDataW.h>
#include <C_CkMimeW.h>
void ChilkatSample(void)
{
BOOL success;
HCkBinDataW bd;
HCkMimeW mime;
success = FALSE;
// Demonstrates the Mime.SetBodyBd method, which sets the decoded body bytes from a BinData,
// changes the transfer encoding to base64, and preserves the bytes exactly. The only argument is
// the BinData.
// Put the binary body bytes into a BinData.
bd = CkBinDataW_Create();
success = CkBinDataW_LoadFile(bd,L"qa_data/photo.jpg");
if (success == FALSE) {
wprintf(L"%s\n",CkBinDataW_lastErrorText(bd));
CkBinDataW_Dispose(bd);
return;
}
mime = CkMimeW_Create();
// Set a Content-Type for the binary content (SetBodyBd does not set one itself).
CkMimeW_putContentType(mime,L"image/jpeg");
success = CkMimeW_SetBodyBd(mime,bd);
if (success == FALSE) {
wprintf(L"%s\n",CkMimeW_lastErrorText(mime));
CkBinDataW_Dispose(bd);
CkMimeW_Dispose(mime);
return;
}
wprintf(L"Body set from %d bytes.\n",CkBinDataW_getNumBytes(bd));
CkBinDataW_Dispose(bd);
CkMimeW_Dispose(mime);
}