PowerBuilder
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Bd
oleobject loo_Mime
li_Success = 0
// 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.
loo_Bd = create oleobject
li_rc = loo_Bd.ConnectToNewObject("Chilkat.BinData")
if li_rc < 0 then
destroy loo_Bd
MessageBox("Error","Connecting to COM object failed")
return
end if
li_Success = loo_Bd.LoadFile("qa_data/photo.jpg")
if li_Success = 0 then
Write-Debug loo_Bd.LastErrorText
destroy loo_Bd
return
end if
loo_Mime = create oleobject
li_rc = loo_Mime.ConnectToNewObject("Chilkat.Mime")
// Set a Content-Type for the binary content (SetBodyBd does not set one itself).
loo_Mime.ContentType = "image/jpeg"
li_Success = loo_Mime.SetBodyBd(loo_Bd)
if li_Success = 0 then
Write-Debug loo_Mime.LastErrorText
destroy loo_Bd
destroy loo_Mime
return
end if
Write-Debug "Body set from " + string(loo_Bd.NumBytes) + " bytes."
destroy loo_Bd
destroy loo_Mime