Sample code for 30+ languages & platforms
SQL Server

Decode Base64 to Zip File

See more Base64 Examples

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.

Chilkat SQL Server Downloads

SQL Server
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @success int
    SELECT @success = 0

    DECLARE @b64 nvarchar(4000)
    SELECT @b64 = 'UEsDBBQA ... AAALgQAAAAA'

    DECLARE @zipData int
    EXEC @hr = sp_OACreate 'Chilkat.BinData', @zipData OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    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