C
C
Set MIME Body from File
See more MIME Examples
Creates a MIME document and sets the body to the contents of a JPG image file. Demonstrates how the Content-Type and Content-Transfer-Encoding fields are automatically set.Chilkat C Downloads
#include <C_CkMime.h>
void ChilkatSample(void)
{
BOOL success;
HCkMime mime;
success = FALSE;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
mime = CkMime_Create();
// The call to SetBodyFromFile automatically adds/updates the following
// header fields based on the file extension:
// Content-Disposition
// Content-Type
// Content-Transfer-Encoding
success = CkMime_SetBodyFromFile(mime,"qa_data/jpg/starfish20.jpg");
if (success != TRUE) {
printf("%s\n",CkMime_lastErrorText(mime));
CkMime_Dispose(mime);
return;
}
// Show the MIME.
printf("%s\n",CkMime_getMime(mime));
// Save this MIME to a file.
success = CkMime_SaveMime(mime,"qa_data/mime/starfish20_base64.mim");
// The MIME that is created is as follows:
// Content-Disposition: attachment; filename="starfish20.jpg"
// Content-Type: image/jpeg; name="starfish20.jpg"
// Content-Transfer-Encoding: base64
//
// /9j/4AAQSkZJRgABAQEASABIAAD//gAmRmlsZSB3cml0dGVuIGJ5IEFkb2JlIFBob3Rvc2hvcD8g
// NC4w/9sAQwAQCwwODAoQDg0OEhEQExgoGhgWFhgxIyUdKDozPTw5Mzg3QEhcTkBEV0U3OFBtUVdf
// YmdoZz5NcXlwZHhcZWdj/9sAQwEREhIYFRgvGhovY0I4QmNjY2NjY2NjY2NjY2NjY2NjY2NjY2Nj
// Y2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2Nj/8IAEQgAFAAUAwERAAIRAQMRAf/EABcAAAMBAAAA
// AAAAAAAAAAAAAAIDBAX/xAAYAQADAQEAAAAAAAAAAAAAAAABAgMEAP/aAAwDAQACEAMQAAAB2kZY
// NNEijWKddfTmLgALWH//xAAbEAACAgMBAAAAAAAAAAAAAAABAgMRAAQSE//aAAgBAQABBQL0XqN+
// pM2aqJGMiqFFCyg7z//EABwRAAICAgMAAAAAAAAAAAAAAAERAAIQIQMSU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