Sample code for 30+ languages & platforms
Visual FoxPro

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 Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loMime

lnSuccess = 0

* This example requires the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.

loMime = CreateObject('Chilkat.Mime')

* The call to SetBodyFromFile automatically adds/updates the following
* header fields based on the file extension:
* Content-Disposition
* Content-Type
* Content-Transfer-Encoding
lnSuccess = loMime.SetBodyFromFile("qa_data/jpg/starfish20.jpg")
IF (lnSuccess <> 1) THEN
    ? loMime.LastErrorText
    RELEASE loMime
    CANCEL
ENDIF

* Show the MIME.
? loMime.GetMime()

* Save this MIME to a file.
lnSuccess = loMime.SaveMime("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//EABwRAAICAgMAAAAAA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