SQL Server
SQL Server
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 SQL Server Downloads
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @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.
DECLARE @bd int
EXEC @hr = sp_OACreate 'Chilkat.BinData', @bd OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
EXEC sp_OAMethod @bd, 'LoadFile', @success OUT, 'qa_data/photo.jpg'
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @bd, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @bd
RETURN
END
DECLARE @mime int
EXEC @hr = sp_OACreate 'Chilkat.Mime', @mime OUT
-- Set a Content-Type for the binary content (SetBodyBd does not set one itself).
EXEC sp_OASetProperty @mime, 'ContentType', 'image/jpeg'
EXEC sp_OAMethod @mime, 'SetBodyBd', @success OUT, @bd
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @mime, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @bd
EXEC @hr = sp_OADestroy @mime
RETURN
END
EXEC sp_OAGetProperty @bd, 'NumBytes', @iTmp0 OUT
PRINT 'Body set from ' + @iTmp0 + ' bytes.'
EXEC @hr = sp_OADestroy @bd
EXEC @hr = sp_OADestroy @mime
END
GO