Azure Blob: Upload Blocks and Commit
See more Azure Cloud Storage Examples
Stage 4 MiB blocks and commit them in order. The current service limits are 4,000 MiB per block and 50,000 committed blocks; this example chooses smaller blocks to bound memory. Every block ID has the same decoded length, includes a per-upload prefix, and is passed as the lowercase blockid query parameter through AddQueryParam for correct escaping.
Only the commit makes the new content visible. If-None-Match on commit prevents replacing an existing blob. A failed staging or commit can leave uncommitted blocks; this sample is not a checkpoint/resume implementation. Prevent concurrent writers and do not change the source while uploading. An empty input commits an empty list.
Uses direct Chilkat REST calls with HTTPS certificate verification. Shared Key examples load a private qa_data/azure/storage.json file containing string fields account and access_key (the base64 account key). SAS consumers need only account there. Create local input/output directories before running. Examples target Azure public-cloud endpoints; adapt hostnames for other clouds or custom endpoints.
REST examples pin x-ms-version: 2026-04-06, and SAS generation uses the same service version. Complete-URL downloads use the supplied SAS version. This is a fully deployed version documented by Microsoft at review time. Older supported versions are not automatically obsolete. Transport completion and HTTP success are checked separately; writes are not automatically replayed after a lost response. Keep diagnostic dumps, keys and SAS URLs private.
Shared Key remains supported where allowed by account policy. Microsoft recommends Microsoft Entra ID, preferably managed identities where available, and user delegation SAS for delegated Blob access. Account-key SAS and Shared Key requests can be rejected when Shared Key access is disabled; these samples do not bypass that policy. See Azure data authorization.
Microsoft put block list reference.
Chilkat SQL Server Downloads
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
-- StringBuilder compares text by value in every generated language.
DECLARE @textCompare int
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @textCompare OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
-- Assumes Chilkat is unlocked. See Global Unlock Sample.
SELECT @success = 0
DECLARE @config int
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @config OUT
EXEC sp_OASetProperty @config, 'Strict', 1
EXEC sp_OAMethod @config, 'LoadFile', @success OUT, 'qa_data/azure/storage.json'
IF @success <> 1
BEGIN
PRINT 'Could not load private Azure configuration.'
EXEC @hr = sp_OADestroy @textCompare
EXEC @hr = sp_OADestroy @config
RETURN
END
EXEC sp_OAMethod @textCompare, 'Clear', NULL
EXEC sp_OAMethod @config, 'StringOf', @sTmp0 OUT, 'account'
EXEC sp_OAMethod @textCompare, 'SetString', @success OUT, @sTmp0
DECLARE @sameText1 int
EXEC sp_OAMethod @textCompare, 'ContentsEqual', @sameText1 OUT, '', 1
EXEC sp_OAMethod @config, 'JsonTypeOf', @iTmp0 OUT, 'account'
IF (@iTmp0 <> 1) or (@sameText1 = 1)
BEGIN
PRINT 'Supply the storage account name.'
EXEC @hr = sp_OADestroy @textCompare
EXEC @hr = sp_OADestroy @config
RETURN
END
-- access_key is the base64 account key, not a connection string or SAS.
EXEC sp_OAMethod @textCompare, 'Clear', NULL
EXEC sp_OAMethod @config, 'StringOf', @sTmp0 OUT, 'access_key'
EXEC sp_OAMethod @textCompare, 'SetString', @success OUT, @sTmp0
DECLARE @sameText2 int
EXEC sp_OAMethod @textCompare, 'ContentsEqual', @sameText2 OUT, '', 1
EXEC sp_OAMethod @config, 'JsonTypeOf', @iTmp0 OUT, 'access_key'
IF (@iTmp0 <> 1) or (@sameText2 = 1)
BEGIN
PRINT 'Supply the base64 account access key.'
EXEC @hr = sp_OADestroy @textCompare
EXEC @hr = sp_OADestroy @config
RETURN
END
DECLARE @endpoint int
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @endpoint OUT
EXEC sp_OAMethod @config, 'StringOf', @sTmp0 OUT, 'account'
EXEC sp_OAMethod @endpoint, 'Append', @success OUT, @sTmp0
IF @success <> 1
BEGIN
PRINT 'Could not prepare the request.'
EXEC @hr = sp_OADestroy @textCompare
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @endpoint
RETURN
END
EXEC sp_OAMethod @endpoint, 'Append', @success OUT, '.blob.core.windows.net'
IF @success <> 1
BEGIN
PRINT 'Could not prepare the request.'
EXEC @hr = sp_OADestroy @textCompare
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @endpoint
RETURN
END
-- resourcePath is already URL-encoded. Encode each path segment once when adapting it.
-- Keep slash separators; names and paths are case-sensitive.
DECLARE @resourcePath nvarchar(4000)
SELECT @resourcePath = '/examplecontainer/example.bin'
DECLARE @rest int
EXEC @hr = sp_OACreate 'Chilkat.Rest', @rest OUT
EXEC sp_OASetProperty @rest, 'ConnectTimeoutMs', 20000
EXEC sp_OASetProperty @rest, 'IdleTimeoutMs', 60000
DECLARE @azAuth int
EXEC @hr = sp_OACreate 'Chilkat.AuthAzureStorage', @azAuth OUT
EXEC sp_OAMethod @config, 'StringOf', @sTmp0 OUT, 'account'
EXEC sp_OASetProperty @azAuth, 'Account', @sTmp0
EXEC sp_OAMethod @config, 'StringOf', @sTmp0 OUT, 'access_key'
EXEC sp_OASetProperty @azAuth, 'AccessKey', @sTmp0
EXEC sp_OASetProperty @azAuth, 'Service', 'Blob'
EXEC sp_OASetProperty @azAuth, 'Scheme', 'SharedKey'
EXEC sp_OASetProperty @azAuth, 'XMsVersion', '2026-04-06'
EXEC sp_OAMethod @rest, 'SetAuthAzureStorage', @success OUT, @azAuth
IF @success <> 1
BEGIN
PRINT 'Could not configure Shared Key signing.'
EXEC @hr = sp_OADestroy @textCompare
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @endpoint
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @azAuth
RETURN
END
DECLARE @connection int
EXEC @hr = sp_OACreate 'Chilkat.Socket', @connection OUT
EXEC sp_OASetProperty @connection, 'RequireSslCertVerify', 1
EXEC sp_OASetProperty @connection, 'MaxReadIdleMs', 60000
EXEC sp_OASetProperty @connection, 'MaxSendIdleMs', 60000
EXEC sp_OAMethod @endpoint, 'GetAsString', @sTmp0 OUT
EXEC sp_OAMethod @connection, 'Connect', @success OUT, @sTmp0, 443, 1, 20000
IF @success <> 1
BEGIN
PRINT 'TLS connection failed; inspect diagnostics privately.'
EXEC @hr = sp_OADestroy @textCompare
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @endpoint
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @azAuth
EXEC @hr = sp_OADestroy @connection
RETURN
END
-- Do not replay a write automatically after losing its response.
EXEC sp_OAMethod @rest, 'UseConnection', @success OUT, @connection, 0
IF @success <> 1
BEGIN
PRINT 'Could not prepare the request.'
EXEC @hr = sp_OADestroy @textCompare
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @endpoint
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @azAuth
EXEC @hr = sp_OADestroy @connection
RETURN
END
DECLARE @responseText nvarchar(4000)
DECLARE @responseBody int
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @responseBody OUT
DECLARE @result int
EXEC @hr = sp_OACreate 'Chilkat.Xml', @result OUT
EXEC sp_OASetProperty @result, 'Strict', 1
DECLARE @input int
EXEC @hr = sp_OACreate 'Chilkat.FileAccess', @input OUT
EXEC sp_OAMethod @input, 'OpenForRead', @success OUT, 'qa_data/bin/sample.bin'
IF @success <> 1
BEGIN
PRINT 'Could not open input.'
EXEC sp_OAMethod @input, 'FileClose', NULL
EXEC @hr = sp_OADestroy @textCompare
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @endpoint
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @azAuth
EXEC @hr = sp_OADestroy @connection
EXEC @hr = sp_OADestroy @responseBody
EXEC @hr = sp_OADestroy @result
EXEC @hr = sp_OADestroy @input
RETURN
END
DECLARE @blockSize int
SELECT @blockSize = 4194304
DECLARE @numBlocks int
EXEC sp_OAMethod @input, 'GetNumBlocks', @numBlocks OUT, @blockSize
IF (@numBlocks < 0) or (@numBlocks > 50000)
BEGIN
PRINT 'Input exceeds the demonstration block limit.'
EXEC sp_OAMethod @input, 'FileClose', NULL
EXEC @hr = sp_OADestroy @textCompare
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @endpoint
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @azAuth
EXEC @hr = sp_OADestroy @connection
EXEC @hr = sp_OADestroy @responseBody
EXEC @hr = sp_OADestroy @result
EXEC @hr = sp_OADestroy @input
RETURN
END
DECLARE @random int
EXEC @hr = sp_OACreate 'Chilkat.Crypt2', @random OUT
DECLARE @uploadId nvarchar(4000)
EXEC sp_OAMethod @random, 'GenerateUuid', @uploadId OUT
EXEC sp_OAGetProperty @random, 'LastMethodSuccess', @iTmp0 OUT
IF @iTmp0 <> 1
BEGIN
PRINT 'Could not create upload ID.'
EXEC sp_OAMethod @input, 'FileClose', NULL
EXEC @hr = sp_OADestroy @textCompare
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @endpoint
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @azAuth
EXEC @hr = sp_OADestroy @connection
EXEC @hr = sp_OADestroy @responseBody
EXEC @hr = sp_OADestroy @result
EXEC @hr = sp_OADestroy @input
EXEC @hr = sp_OADestroy @random
RETURN
END
-- Persist uploadId, block IDs and the unchanged source fingerprint to implement resumption.
DECLARE @blocks int
EXEC @hr = sp_OACreate 'Chilkat.Xml', @blocks OUT
EXEC sp_OASetProperty @blocks, 'Tag', 'BlockList'
DECLARE @chunk int
EXEC @hr = sp_OACreate 'Chilkat.BinData', @chunk OUT
DECLARE @blockText int
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @blockText OUT
DECLARE @i int
SELECT @i = 0
WHILE (@i < @numBlocks)
BEGIN
EXEC sp_OAMethod @chunk, 'Clear', @success OUT
IF @success <> 1
BEGIN
PRINT 'Could not prepare the request.'
EXEC sp_OAMethod @input, 'FileClose', NULL
EXEC @hr = sp_OADestroy @textCompare
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @endpoint
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @azAuth
EXEC @hr = sp_OADestroy @connection
EXEC @hr = sp_OADestroy @responseBody
EXEC @hr = sp_OADestroy @result
EXEC @hr = sp_OADestroy @input
EXEC @hr = sp_OADestroy @random
EXEC @hr = sp_OADestroy @blocks
EXEC @hr = sp_OADestroy @chunk
EXEC @hr = sp_OADestroy @blockText
RETURN
END
EXEC sp_OAMethod @input, 'ReadBlockBd', @success OUT, @i, @blockSize, @chunk
IF @success <> 1
BEGIN
PRINT 'Failed to read block.'
EXEC sp_OAMethod @input, 'FileClose', NULL
EXEC @hr = sp_OADestroy @textCompare
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @endpoint
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @azAuth
EXEC @hr = sp_OADestroy @connection
EXEC @hr = sp_OADestroy @responseBody
EXEC @hr = sp_OADestroy @result
EXEC @hr = sp_OADestroy @input
EXEC @hr = sp_OADestroy @random
EXEC @hr = sp_OADestroy @blocks
EXEC @hr = sp_OADestroy @chunk
EXEC @hr = sp_OADestroy @blockText
RETURN
END
EXEC sp_OAMethod @blockText, 'Clear', NULL
EXEC sp_OAMethod @blockText, 'Append', @success OUT, @uploadId
IF @success <> 1
BEGIN
PRINT 'Could not prepare the request.'
EXEC sp_OAMethod @input, 'FileClose', NULL
EXEC @hr = sp_OADestroy @textCompare
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @endpoint
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @azAuth
EXEC @hr = sp_OADestroy @connection
EXEC @hr = sp_OADestroy @responseBody
EXEC @hr = sp_OADestroy @result
EXEC @hr = sp_OADestroy @input
EXEC @hr = sp_OADestroy @random
EXEC @hr = sp_OADestroy @blocks
EXEC @hr = sp_OADestroy @chunk
EXEC @hr = sp_OADestroy @blockText
RETURN
END
EXEC sp_OAMethod @input, 'GenBlockId', @sTmp0 OUT, @i, 5, 'ascii'
EXEC sp_OAMethod @blockText, 'Append', @success OUT, @sTmp0
IF @success <> 1
BEGIN
PRINT 'Could not prepare the request.'
EXEC sp_OAMethod @input, 'FileClose', NULL
EXEC @hr = sp_OADestroy @textCompare
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @endpoint
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @azAuth
EXEC @hr = sp_OADestroy @connection
EXEC @hr = sp_OADestroy @responseBody
EXEC @hr = sp_OADestroy @result
EXEC @hr = sp_OADestroy @input
EXEC @hr = sp_OADestroy @random
EXEC @hr = sp_OADestroy @blocks
EXEC @hr = sp_OADestroy @chunk
EXEC @hr = sp_OADestroy @blockText
RETURN
END
EXEC sp_OAMethod @blockText, 'Encode', @success OUT, 'base64', 'utf-8'
IF @success <> 1
BEGIN
PRINT 'Could not prepare the request.'
EXEC sp_OAMethod @input, 'FileClose', NULL
EXEC @hr = sp_OADestroy @textCompare
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @endpoint
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @azAuth
EXEC @hr = sp_OADestroy @connection
EXEC @hr = sp_OADestroy @responseBody
EXEC @hr = sp_OADestroy @result
EXEC @hr = sp_OADestroy @input
EXEC @hr = sp_OADestroy @random
EXEC @hr = sp_OADestroy @blocks
EXEC @hr = sp_OADestroy @chunk
EXEC @hr = sp_OADestroy @blockText
RETURN
END
DECLARE @blockId nvarchar(4000)
EXEC sp_OAMethod @blockText, 'GetAsString', @blockId OUT
EXEC sp_OAMethod @rest, 'ClearAllQueryParams', @success OUT
IF @success <> 1
BEGIN
PRINT 'Could not prepare the request.'
EXEC sp_OAMethod @input, 'FileClose', NULL
EXEC @hr = sp_OADestroy @textCompare
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @endpoint
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @azAuth
EXEC @hr = sp_OADestroy @connection
EXEC @hr = sp_OADestroy @responseBody
EXEC @hr = sp_OADestroy @result
EXEC @hr = sp_OADestroy @input
EXEC @hr = sp_OADestroy @random
EXEC @hr = sp_OADestroy @blocks
EXEC @hr = sp_OADestroy @chunk
EXEC @hr = sp_OADestroy @blockText
RETURN
END
EXEC sp_OAMethod @rest, 'AddQueryParam', @success OUT, 'comp', 'block'
IF @success <> 1
BEGIN
PRINT 'Could not prepare the request.'
EXEC sp_OAMethod @input, 'FileClose', NULL
EXEC @hr = sp_OADestroy @textCompare
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @endpoint
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @azAuth
EXEC @hr = sp_OADestroy @connection
EXEC @hr = sp_OADestroy @responseBody
EXEC @hr = sp_OADestroy @result
EXEC @hr = sp_OADestroy @input
EXEC @hr = sp_OADestroy @random
EXEC @hr = sp_OADestroy @blocks
EXEC @hr = sp_OADestroy @chunk
EXEC @hr = sp_OADestroy @blockText
RETURN
END
EXEC sp_OAMethod @rest, 'AddQueryParam', @success OUT, 'blockid', @blockId
IF @success <> 1
BEGIN
PRINT 'Could not prepare the request.'
EXEC sp_OAMethod @input, 'FileClose', NULL
EXEC @hr = sp_OADestroy @textCompare
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @endpoint
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @azAuth
EXEC @hr = sp_OADestroy @connection
EXEC @hr = sp_OADestroy @responseBody
EXEC @hr = sp_OADestroy @result
EXEC @hr = sp_OADestroy @input
EXEC @hr = sp_OADestroy @random
EXEC @hr = sp_OADestroy @blocks
EXEC @hr = sp_OADestroy @chunk
EXEC @hr = sp_OADestroy @blockText
RETURN
END
EXEC sp_OAMethod @responseBody, 'Clear', NULL
EXEC sp_OAMethod @rest, 'FullRequestBd', @success OUT, 'PUT', @resourcePath, @chunk, @responseBody
IF @success <> 1
BEGIN
PRINT 'Request did not complete; outcome may be uncertain.'
EXEC sp_OAMethod @input, 'FileClose', NULL
EXEC @hr = sp_OADestroy @textCompare
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @endpoint
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @azAuth
EXEC @hr = sp_OADestroy @connection
EXEC @hr = sp_OADestroy @responseBody
EXEC @hr = sp_OADestroy @result
EXEC @hr = sp_OADestroy @input
EXEC @hr = sp_OADestroy @random
EXEC @hr = sp_OADestroy @blocks
EXEC @hr = sp_OADestroy @chunk
EXEC @hr = sp_OADestroy @blockText
RETURN
END
EXEC sp_OAGetProperty @rest, 'ResponseStatusCode', @iTmp0 OUT
IF @iTmp0 <> 201
BEGIN
EXEC sp_OAGetProperty @rest, 'ResponseStatusCode', @iTmp0 OUT
PRINT 'HTTP status: ' + @iTmp0
EXEC sp_OAMethod @rest, 'ResponseHdrByName', @sTmp0 OUT, 'x-ms-error-code'
PRINT 'Azure error code: ' + @sTmp0
EXEC sp_OAMethod @rest, 'ResponseHdrByName', @sTmp0 OUT, 'x-ms-request-id'
PRINT 'Request ID: ' + @sTmp0
-- Inspect any error body privately; do not log credentials, SAS URLs or payloads.
EXEC sp_OAMethod @input, 'FileClose', NULL
EXEC @hr = sp_OADestroy @textCompare
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @endpoint
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @azAuth
EXEC @hr = sp_OADestroy @connection
EXEC @hr = sp_OADestroy @responseBody
EXEC @hr = sp_OADestroy @result
EXEC @hr = sp_OADestroy @input
EXEC @hr = sp_OADestroy @random
EXEC @hr = sp_OADestroy @blocks
EXEC @hr = sp_OADestroy @chunk
EXEC @hr = sp_OADestroy @blockText
RETURN
END
-- Add only a successfully staged block, in source order.
EXEC sp_OAMethod @blocks, 'NewChild2', NULL, 'Uncommitted', @blockId
SELECT @i = @i + 1
EXEC sp_OAMethod @rest, 'Disconnect', @success OUT, 10
EXEC sp_OAMethod @endpoint, 'GetAsString', @sTmp0 OUT
EXEC sp_OAMethod @connection, 'Connect', @success OUT, @sTmp0, 443, 1, 20000
IF @success <> 1
BEGIN
PRINT 'TLS reconnection failed.'
EXEC sp_OAMethod @input, 'FileClose', NULL
EXEC @hr = sp_OADestroy @textCompare
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @endpoint
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @azAuth
EXEC @hr = sp_OADestroy @connection
EXEC @hr = sp_OADestroy @responseBody
EXEC @hr = sp_OADestroy @result
EXEC @hr = sp_OADestroy @input
EXEC @hr = sp_OADestroy @random
EXEC @hr = sp_OADestroy @blocks
EXEC @hr = sp_OADestroy @chunk
EXEC @hr = sp_OADestroy @blockText
RETURN
END
EXEC sp_OAMethod @rest, 'UseConnection', @success OUT, @connection, 0
IF @success <> 1
BEGIN
PRINT 'Could not prepare the request.'
EXEC sp_OAMethod @input, 'FileClose', NULL
EXEC @hr = sp_OADestroy @textCompare
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @endpoint
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @azAuth
EXEC @hr = sp_OADestroy @connection
EXEC @hr = sp_OADestroy @responseBody
EXEC @hr = sp_OADestroy @result
EXEC @hr = sp_OADestroy @input
EXEC @hr = sp_OADestroy @random
EXEC @hr = sp_OADestroy @blocks
EXEC @hr = sp_OADestroy @chunk
EXEC @hr = sp_OADestroy @blockText
RETURN
END
END
EXEC sp_OAMethod @input, 'FileClose', NULL
EXEC sp_OAMethod @rest, 'ClearAllQueryParams', @success OUT
IF @success <> 1
BEGIN
PRINT 'Could not prepare the request.'
EXEC @hr = sp_OADestroy @textCompare
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @endpoint
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @azAuth
EXEC @hr = sp_OADestroy @connection
EXEC @hr = sp_OADestroy @responseBody
EXEC @hr = sp_OADestroy @result
EXEC @hr = sp_OADestroy @input
EXEC @hr = sp_OADestroy @random
EXEC @hr = sp_OADestroy @blocks
EXEC @hr = sp_OADestroy @chunk
EXEC @hr = sp_OADestroy @blockText
RETURN
END
EXEC sp_OAMethod @rest, 'AddQueryParam', @success OUT, 'comp', 'blocklist'
IF @success <> 1
BEGIN
PRINT 'Could not prepare the request.'
EXEC @hr = sp_OADestroy @textCompare
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @endpoint
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @azAuth
EXEC @hr = sp_OADestroy @connection
EXEC @hr = sp_OADestroy @responseBody
EXEC @hr = sp_OADestroy @result
EXEC @hr = sp_OADestroy @input
EXEC @hr = sp_OADestroy @random
EXEC @hr = sp_OADestroy @blocks
EXEC @hr = sp_OADestroy @chunk
EXEC @hr = sp_OADestroy @blockText
RETURN
END
EXEC sp_OAMethod @rest, 'AddHeader', @success OUT, 'Content-Type', 'application/xml'
IF @success <> 1
BEGIN
PRINT 'Could not prepare the request.'
EXEC @hr = sp_OADestroy @textCompare
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @endpoint
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @azAuth
EXEC @hr = sp_OADestroy @connection
EXEC @hr = sp_OADestroy @responseBody
EXEC @hr = sp_OADestroy @result
EXEC @hr = sp_OADestroy @input
EXEC @hr = sp_OADestroy @random
EXEC @hr = sp_OADestroy @blocks
EXEC @hr = sp_OADestroy @chunk
EXEC @hr = sp_OADestroy @blockText
RETURN
END
EXEC sp_OAMethod @rest, 'AddHeader', @success OUT, 'x-ms-blob-content-type', 'application/octet-stream'
IF @success <> 1
BEGIN
PRINT 'Could not prepare the request.'
EXEC @hr = sp_OADestroy @textCompare
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @endpoint
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @azAuth
EXEC @hr = sp_OADestroy @connection
EXEC @hr = sp_OADestroy @responseBody
EXEC @hr = sp_OADestroy @result
EXEC @hr = sp_OADestroy @input
EXEC @hr = sp_OADestroy @random
EXEC @hr = sp_OADestroy @blocks
EXEC @hr = sp_OADestroy @chunk
EXEC @hr = sp_OADestroy @blockText
RETURN
END
EXEC sp_OAMethod @rest, 'AddHeader', @success OUT, 'If-None-Match', '*'
IF @success <> 1
BEGIN
PRINT 'Could not prepare the request.'
EXEC @hr = sp_OADestroy @textCompare
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @endpoint
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @azAuth
EXEC @hr = sp_OADestroy @connection
EXEC @hr = sp_OADestroy @responseBody
EXEC @hr = sp_OADestroy @result
EXEC @hr = sp_OADestroy @input
EXEC @hr = sp_OADestroy @random
EXEC @hr = sp_OADestroy @blocks
EXEC @hr = sp_OADestroy @chunk
EXEC @hr = sp_OADestroy @blockText
RETURN
END
EXEC sp_OAMethod @blocks, 'GetXml', @sTmp0 OUT
EXEC sp_OAMethod @rest, 'FullRequestString', @responseText OUT, 'PUT', @resourcePath, @sTmp0
EXEC sp_OAGetProperty @rest, 'LastMethodSuccess', @iTmp0 OUT
IF @iTmp0 <> 1
BEGIN
PRINT 'Request did not complete; outcome may be uncertain.'
EXEC @hr = sp_OADestroy @textCompare
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @endpoint
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @azAuth
EXEC @hr = sp_OADestroy @connection
EXEC @hr = sp_OADestroy @responseBody
EXEC @hr = sp_OADestroy @result
EXEC @hr = sp_OADestroy @input
EXEC @hr = sp_OADestroy @random
EXEC @hr = sp_OADestroy @blocks
EXEC @hr = sp_OADestroy @chunk
EXEC @hr = sp_OADestroy @blockText
RETURN
END
EXEC sp_OAGetProperty @rest, 'ResponseStatusCode', @iTmp0 OUT
IF @iTmp0 <> 201
BEGIN
EXEC sp_OAGetProperty @rest, 'ResponseStatusCode', @iTmp0 OUT
PRINT 'HTTP status: ' + @iTmp0
EXEC sp_OAMethod @rest, 'ResponseHdrByName', @sTmp0 OUT, 'x-ms-error-code'
PRINT 'Azure error code: ' + @sTmp0
EXEC sp_OAMethod @rest, 'ResponseHdrByName', @sTmp0 OUT, 'x-ms-request-id'
PRINT 'Request ID: ' + @sTmp0
-- Inspect any error body privately; do not log credentials, SAS URLs or payloads.
EXEC @hr = sp_OADestroy @textCompare
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @endpoint
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @azAuth
EXEC @hr = sp_OADestroy @connection
EXEC @hr = sp_OADestroy @responseBody
EXEC @hr = sp_OADestroy @result
EXEC @hr = sp_OADestroy @input
EXEC @hr = sp_OADestroy @random
EXEC @hr = sp_OADestroy @blocks
EXEC @hr = sp_OADestroy @chunk
EXEC @hr = sp_OADestroy @blockText
RETURN
END
PRINT 'Block list committed; blob created.'
EXEC @hr = sp_OADestroy @textCompare
EXEC @hr = sp_OADestroy @config
EXEC @hr = sp_OADestroy @endpoint
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @azAuth
EXEC @hr = sp_OADestroy @connection
EXEC @hr = sp_OADestroy @responseBody
EXEC @hr = sp_OADestroy @result
EXEC @hr = sp_OADestroy @input
EXEC @hr = sp_OADestroy @random
EXEC @hr = sp_OADestroy @blocks
EXEC @hr = sp_OADestroy @chunk
EXEC @hr = sp_OADestroy @blockText
END
GO