Azure Blob: Upload a File Using a Complete SAS URL
See more Azure Cloud Storage Examples
Use a complete privately supplied HTTPS URL containing a valid SAS for the exact blob. This works with an appropriate service, account, or user delegation SAS; the consumer does not need the account key. The earlier embedded, expired token is removed. The required permission is create/write; If-None-Match prevents replacing an existing blob.
Keep the URL private and do not alter or double-encode the signature query. Redirects are disabled. This example uses Chilkat.Http directly for the full-URL convenience method; the other transfer examples show Chilkat.Rest.
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.
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 @success int
SELECT @success = 0
-- Use a privately supplied COMPLETE HTTPS blob URL with a current SAS query.
-- No account key is needed by this consumer.
SELECT @success = 0
DECLARE @savedUrl int
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @savedUrl OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
EXEC sp_OAMethod @savedUrl, 'LoadFile', @success OUT, 'qa_data/azure/blob-url.txt', 'utf-8'
IF @success <> 1
BEGIN
PRINT 'Could not load private SAS URL.'
EXEC @hr = sp_OADestroy @savedUrl
RETURN
END
EXEC sp_OAMethod @savedUrl, 'Trim', @success OUT
IF @success <> 1
BEGIN
PRINT 'Could not prepare the request.'
EXEC @hr = sp_OADestroy @savedUrl
RETURN
END
EXEC sp_OAMethod @savedUrl, 'StartsWith', @iTmp0 OUT, 'https://', 0
IF @iTmp0 <> 1
BEGIN
PRINT 'An HTTPS SAS URL is required.'
EXEC @hr = sp_OADestroy @savedUrl
RETURN
END
DECLARE @url nvarchar(4000)
EXEC sp_OAMethod @savedUrl, 'GetAsString', @url OUT
DECLARE @http int
EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
EXEC sp_OASetProperty @http, 'RequireSslCertVerify', 1
EXEC sp_OASetProperty @http, 'FollowRedirects', 0
EXEC sp_OASetProperty @http, 'ConnectTimeout', 20
EXEC sp_OASetProperty @http, 'ReadTimeout', 60
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'x-ms-version', '2026-04-06'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'x-ms-blob-type', 'BlockBlob'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'If-None-Match', '*'
DECLARE @response int
EXEC @hr = sp_OACreate 'Chilkat.HttpResponse', @response OUT
EXEC sp_OAMethod @http, 'HttpFile', @success OUT, 'PUT', @url, 'qa_data/bin/sample.bin', 'application/octet-stream', @response
IF @success <> 1
BEGIN
PRINT 'Upload did not complete; inspect diagnostics privately.'
EXEC @hr = sp_OADestroy @savedUrl
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @response
RETURN
END
EXEC sp_OAGetProperty @response, 'StatusCode', @iTmp0 OUT
IF @iTmp0 <> 201
BEGIN
PRINT 'Upload rejected; inspect HTTP status and Azure error code privately.'
EXEC @hr = sp_OADestroy @savedUrl
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @response
RETURN
END
PRINT 'Blob created using the supplied SAS URL.'
EXEC @hr = sp_OADestroy @savedUrl
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @response
END
GO