(SQL Server) Decode Base64 to Zip File
Shows how to decode a baes64 string that is the encoded representation of the bytes that make up a .zip archive. Decodes the base64 and writes the .zip file.
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @b64 nvarchar(4000)
SELECT @b64 = 'UEsDBBQA ... AAALgQAAAAA'
DECLARE @zipData int
-- Use "Chilkat_9_5_0.BinData" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.BinData', @zipData OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @success int
EXEC sp_OAMethod @zipData, 'AppendEncoded', @success OUT, @b64, 'base64'
EXEC sp_OAMethod @zipData, 'WriteFile', @success OUT, 'qa_output/out.zip'
IF @success <> 1
BEGIN
PRINT 'failed to write Zip file.'
EXEC @hr = sp_OADestroy @zipData
RETURN
END
EXEC @hr = sp_OADestroy @zipData
END
GO
|