Azure Blob: Resume a Block Upload from a Checkpoint
See more Azure Cloud Storage Examples
Persist the destination, source size/SHA-256, block size and unique upload ID before staging any blocks. On a later run, verify the source, get the uncommitted block list, skip matching blocks, upload missing blocks, and commit in source order. Block IDs are derived from the saved upload ID and fixed-width index, so a restart uses the same IDs.
Use one process per checkpoint and keep its source and destination exclusively controlled. The example does not replace an existing blob. Commit metadata lets a restart recognize its own completed upload after an uncertain response; otherwise an existing destination is an error. Remote block size is checked, but the source fingerprint and unique namespace are what associate the blocks with this upload. Stale uncommitted blocks can expire; missing blocks are uploaded again. Empty files commit an empty block list.
The sample uses 4 MiB blocks and at most 50,000 blocks; source sizes stay strings and block indexes use int. It fingerprints the whole source at start and before commit, trading read time for change detection. Keep checkpoint files private and unchanged. A corrupt checkpoint fails closed; choose a fresh checkpoint and destination deliberately rather than discarding state automatically.
Uses direct Chilkat.Rest requests and Azure public-cloud endpoints with verified HTTPS. REST requests select service version 2026-04-06. Create local input/output directories before running. Account-key examples read account and access_key string fields from private qa_data/azure/storage.json; do not embed secrets in distributed applications. Entra examples explain their own configuration. Keep credentials, bearer tokens, SAS URLs and diagnostic dumps private. Shared Key is supported only where allowed by account policy; Entra authentication is preferred where available.
Transport success and HTTP status are checked separately. Writes are not automatically replayed after an uncertain response. IDs, ETags, continuation markers and file sizes are strings; counters and explicitly bounded offsets use int. No webhook or web server is required.
Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoTextCompare
Handle hoConfig
Boolean iSameText1
Boolean iSameText2
Handle hoEndpoint
String sResourcePath
Handle hoRest
Variant vAzAuth
Handle hoAzAuth
Variant vConnection
Handle hoConnection
String sResponseText
Variant vResponseBody
Handle hoResponseBody
Handle hoResult
String sSourceFile
String sCheckpointFile
Handle hoInput
String sSourceSize
Integer iBlockSize
Integer iNumBlocks
Handle hoHash
String sFingerprint
Handle hoCheckpoint
Handle hoFiles
Boolean iSameText3
Boolean iSameText4
Boolean iSameText5
Boolean iSameText6
String sNewId
String sUploadId
Handle hoIdCheck
Boolean iSameText7
Boolean iSameText8
Boolean iSameText9
Boolean iSameText10
Handle hoRemoteBlocks
Integer iRemoteCount
Integer j
String sRemoteId
String sRemoteSize
Boolean iSameText11
Boolean iSameText12
Boolean iSameText13
Handle hoBlocks
Variant vChunk
Handle hoChunk
Handle hoBlockText
Handle hoSizeText
Integer i
String sBlockId
Boolean iUploadBlock
String sFinalFingerprint
Boolean iSameText14
String sTemp1
String sTemp2
Integer iTemp1
Integer iTemp2
Boolean bTemp1
Move False To iSuccess
// StringBuilder compares text by value in every generated language.
Get Create (RefClass(cComChilkatStringBuilder)) To hoTextCompare
If (Not(IsComObjectCreated(hoTextCompare))) Begin
Send CreateComObject of hoTextCompare
End
// Assumes Chilkat is unlocked. See Global Unlock Sample.
Move False To iSuccess
Get Create (RefClass(cComChilkatJsonObject)) To hoConfig
If (Not(IsComObjectCreated(hoConfig))) Begin
Send CreateComObject of hoConfig
End
Set ComStrict Of hoConfig To True
Get ComLoadFile Of hoConfig "qa_data/azure/storage.json" To iSuccess
If (iSuccess <> True) Begin
Showln "Could not load private Azure configuration."
Procedure_Return
End
Send ComClear To hoTextCompare
Get ComStringOf Of hoConfig "account" To sTemp1
Get ComSetString Of hoTextCompare sTemp1 To iSuccess
Get ComContentsEqual Of hoTextCompare "" True To iSameText1
Get ComJsonTypeOf Of hoConfig "account" To iTemp1
If ((iTemp1 <> 1) Or (iSameText1 = True)) Begin
Showln "Supply the storage account name."
Procedure_Return
End
// access_key is the base64 account key, not a connection string or SAS.
Send ComClear To hoTextCompare
Get ComStringOf Of hoConfig "access_key" To sTemp1
Get ComSetString Of hoTextCompare sTemp1 To iSuccess
Get ComContentsEqual Of hoTextCompare "" True To iSameText2
Get ComJsonTypeOf Of hoConfig "access_key" To iTemp1
If ((iTemp1 <> 1) Or (iSameText2 = True)) Begin
Showln "Supply the base64 account access key."
Procedure_Return
End
Get Create (RefClass(cComChilkatStringBuilder)) To hoEndpoint
If (Not(IsComObjectCreated(hoEndpoint))) Begin
Send CreateComObject of hoEndpoint
End
Get ComStringOf Of hoConfig "account" To sTemp1
Get ComAppend Of hoEndpoint sTemp1 To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
Get ComAppend Of hoEndpoint ".blob.core.windows.net" To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
// resourcePath is already URL-encoded. Encode each path segment once when adapting it.
// Keep slash separators; names and paths are case-sensitive.
Move "/examplecontainer/example.bin" To sResourcePath
Get Create (RefClass(cComChilkatRest)) To hoRest
If (Not(IsComObjectCreated(hoRest))) Begin
Send CreateComObject of hoRest
End
Set ComConnectTimeoutMs Of hoRest To 20000
Set ComIdleTimeoutMs Of hoRest To 60000
Get Create (RefClass(cComChilkatAuthAzureStorage)) To hoAzAuth
If (Not(IsComObjectCreated(hoAzAuth))) Begin
Send CreateComObject of hoAzAuth
End
Get ComStringOf Of hoConfig "account" To sTemp1
Set ComAccount Of hoAzAuth To sTemp1
Get ComStringOf Of hoConfig "access_key" To sTemp1
Set ComAccessKey Of hoAzAuth To sTemp1
Set ComService Of hoAzAuth To "Blob"
Set ComScheme Of hoAzAuth To "SharedKey"
Set ComXMsVersion Of hoAzAuth To "2026-04-06"
Get pvComObject of hoAzAuth to vAzAuth
Get ComSetAuthAzureStorage Of hoRest vAzAuth To iSuccess
If (iSuccess <> True) Begin
Showln "Could not configure Shared Key signing."
Procedure_Return
End
Get Create (RefClass(cComChilkatSocket)) To hoConnection
If (Not(IsComObjectCreated(hoConnection))) Begin
Send CreateComObject of hoConnection
End
Set ComRequireSslCertVerify Of hoConnection To True
Set ComMaxReadIdleMs Of hoConnection To 60000
Set ComMaxSendIdleMs Of hoConnection To 60000
Get ComGetAsString Of hoEndpoint To sTemp1
Get ComConnect Of hoConnection sTemp1 443 True 20000 To iSuccess
If (iSuccess <> True) Begin
Showln "TLS connection failed; inspect diagnostics privately."
Procedure_Return
End
// Do not replay a write automatically after losing its response.
Get pvComObject of hoConnection to vConnection
Get ComUseConnection Of hoRest vConnection False To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
Get Create (RefClass(cComChilkatStringBuilder)) To hoResponseBody
If (Not(IsComObjectCreated(hoResponseBody))) Begin
Send CreateComObject of hoResponseBody
End
Get Create (RefClass(cComChilkatXml)) To hoResult
If (Not(IsComObjectCreated(hoResult))) Begin
Send CreateComObject of hoResult
End
Set ComStrict Of hoResult To True
Move "qa_data/bin/sample.bin" To sSourceFile
Move "qa_data/azure/upload-checkpoint.json" To sCheckpointFile
Get Create (RefClass(cComCkFileAccess)) To hoInput
If (Not(IsComObjectCreated(hoInput))) Begin
Send CreateComObject of hoInput
End
Get ComOpenForRead Of hoInput sSourceFile To iSuccess
If (iSuccess <> True) Begin
Showln "Could not open upload source."
Send ComFileClose To hoInput
Procedure_Return
End
Get ComFileSizeStr Of hoInput sSourceFile To sSourceSize
Get ComLastMethodSuccess Of hoInput To bTemp1
If (bTemp1 <> True) Begin
Showln "Could not read source size."
Send ComFileClose To hoInput
Procedure_Return
End
Move 4194304 To iBlockSize
Get ComGetNumBlocks Of hoInput iBlockSize To iNumBlocks
Get ComLastMethodSuccess Of hoInput To bTemp1
If ((bTemp1 <> True) Or (iNumBlocks < 0) Or (iNumBlocks > 50000)) Begin
Showln "Source exceeds the 50,000-block demonstration bound."
Send ComFileClose To hoInput
Procedure_Return
End
Get Create (RefClass(cComChilkatCrypt2)) To hoHash
If (Not(IsComObjectCreated(hoHash))) Begin
Send CreateComObject of hoHash
End
Set ComHashAlgorithm Of hoHash To "sha256"
Set ComEncodingMode Of hoHash To "hex_lower"
Get ComHashFileENC Of hoHash sSourceFile To sFingerprint
Get ComLastMethodSuccess Of hoHash To bTemp1
If (bTemp1 <> True) Begin
Showln "Could not fingerprint source."
Send ComFileClose To hoInput
Procedure_Return
End
Get Create (RefClass(cComChilkatJsonObject)) To hoCheckpoint
If (Not(IsComObjectCreated(hoCheckpoint))) Begin
Send CreateComObject of hoCheckpoint
End
Set ComStrict Of hoCheckpoint To True
Get Create (RefClass(cComCkFileAccess)) To hoFiles
If (Not(IsComObjectCreated(hoFiles))) Begin
Send CreateComObject of hoFiles
End
Get ComFileExists Of hoFiles sCheckpointFile To bTemp1
If (bTemp1 = True) Begin
Get ComLoadFile Of hoCheckpoint sCheckpointFile To iSuccess
If (iSuccess <> True) Begin
Showln "Invalid checkpoint; do not silently start another upload."
Send ComFileClose To hoInput
Procedure_Return
End
Send ComClear To hoTextCompare
Get ComStringOf Of hoCheckpoint "path" To sTemp1
Get ComSetString Of hoTextCompare sTemp1 To iSuccess
Get ComContentsEqual Of hoTextCompare sResourcePath True To iSameText3
Send ComClear To hoTextCompare
Get ComStringOf Of hoCheckpoint "sha256" To sTemp1
Get ComSetString Of hoTextCompare sTemp1 To iSuccess
Get ComContentsEqual Of hoTextCompare sFingerprint True To iSameText4
Send ComClear To hoTextCompare
Get ComStringOf Of hoCheckpoint "size" To sTemp1
Get ComSetString Of hoTextCompare sTemp1 To iSuccess
Get ComContentsEqual Of hoTextCompare sSourceSize True To iSameText5
Get ComStringOf Of hoCheckpoint "account" To sTemp1
Get ComStringOf Of hoConfig "account" To sTemp2
Get ComIntOf Of hoCheckpoint "block_size" To iTemp1
If ((sTemp1 <> sTemp2) Or (iSameText3 <> True) Or (iSameText4 <> True) Or (iSameText5 <> True) Or (iTemp1 <> iBlockSize)) Begin
Showln "Checkpoint target or source changed. Choose a new checkpoint/target deliberately."
Send ComFileClose To hoInput
Procedure_Return
End
Send ComClear To hoTextCompare
Get ComStringOf Of hoCheckpoint "upload_id" To sTemp1
Get ComSetString Of hoTextCompare sTemp1 To iSuccess
Get ComContentsEqual Of hoTextCompare "" True To iSameText6
If (iSameText6 = True) Begin
Showln "Missing checkpoint upload ID."
Send ComFileClose To hoInput
Procedure_Return
End
End
Else Begin
Get ComGenerateUuid Of hoHash To sNewId
Get ComLastMethodSuccess Of hoHash To bTemp1
If (bTemp1 <> True) Begin
Showln "Could not generate upload ID."
Send ComFileClose To hoInput
Procedure_Return
End
Get ComStringOf Of hoConfig "account" To sTemp1
Get ComUpdateString Of hoCheckpoint "account" sTemp1 To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Send ComFileClose To hoInput
Procedure_Return
End
Get ComUpdateString Of hoCheckpoint "path" sResourcePath To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Send ComFileClose To hoInput
Procedure_Return
End
Get ComUpdateString Of hoCheckpoint "sha256" sFingerprint To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Send ComFileClose To hoInput
Procedure_Return
End
Get ComUpdateString Of hoCheckpoint "size" sSourceSize To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Send ComFileClose To hoInput
Procedure_Return
End
Get ComUpdateInt Of hoCheckpoint "block_size" iBlockSize To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Send ComFileClose To hoInput
Procedure_Return
End
Get ComUpdateString Of hoCheckpoint "upload_id" sNewId To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Send ComFileClose To hoInput
Procedure_Return
End
Get ComWriteFile Of hoCheckpoint "qa_data/azure/upload-checkpoint.tmp" To iSuccess
If (iSuccess <> True) Begin
Showln "Could not write checkpoint."
Send ComFileClose To hoInput
Procedure_Return
End
Get ComFileRename Of hoFiles "qa_data/azure/upload-checkpoint.tmp" sCheckpointFile To iSuccess
If (iSuccess <> True) Begin
Showln "Could not publish checkpoint."
Send ComFileClose To hoInput
Procedure_Return
End
End
Get ComStringOf Of hoCheckpoint "upload_id" To sUploadId
Get Create (RefClass(cComChilkatStringBuilder)) To hoIdCheck
If (Not(IsComObjectCreated(hoIdCheck))) Begin
Send CreateComObject of hoIdCheck
End
Get ComAppend Of hoIdCheck sUploadId To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Send ComFileClose To hoInput
Procedure_Return
End
Get ComLength Of hoIdCheck To iTemp1
If (iTemp1 <> 36) Begin
Showln "Invalid upload ID length in checkpoint."
Send ComFileClose To hoInput
Procedure_Return
End
// Reconcile an uncertain commit before staging anything else.
Get ComFullRequestNoBody Of hoRest "HEAD" sResourcePath To sResponseText
Get ComLastMethodSuccess Of hoRest To bTemp1
If (bTemp1 <> True) Begin
Showln "Could not inspect destination."
Send ComFileClose To hoInput
Procedure_Return
End
Get ComResponseStatusCode Of hoRest To iTemp1
If (iTemp1 = 200) Begin
Send ComClear To hoTextCompare
Get ComResponseHdrByName Of hoRest "x-ms-meta-upload-id" To sTemp1
Get ComSetString Of hoTextCompare sTemp1 To iSuccess
Get ComContentsEqual Of hoTextCompare sUploadId True To iSameText7
Send ComClear To hoTextCompare
Get ComResponseHdrByName Of hoRest "x-ms-meta-source-sha256" To sTemp1
Get ComSetString Of hoTextCompare sTemp1 To iSuccess
Get ComContentsEqual Of hoTextCompare sFingerprint True To iSameText8
Send ComClear To hoTextCompare
Get ComResponseHdrByName Of hoRest "Content-Length" To sTemp1
Get ComSetString Of hoTextCompare sTemp1 To iSuccess
Get ComContentsEqual Of hoTextCompare sSourceSize True To iSameText9
If ((iSameText7 <> True) Or (iSameText8 <> True) Or (iSameText9 <> True)) Begin
Showln "Destination exists and is not this completed upload. Refusing to replace it."
Send ComFileClose To hoInput
Procedure_Return
End
Showln "Upload already committed. Keep the checkpoint until the application records completion."
Send ComFileClose To hoInput
Procedure_Return
End
Send ComClear To hoTextCompare
Get ComResponseHdrByName Of hoRest "x-ms-error-code" To sTemp1
Get ComSetString Of hoTextCompare sTemp1 To iSuccess
Get ComContentsEqual Of hoTextCompare "BlobNotFound" True To iSameText10
Get ComResponseStatusCode Of hoRest To iTemp1
If ((iTemp1 <> 404) Or (iSameText10 <> True)) Begin
Showln "Expected an absent blob in an existing container."
Send ComFileClose To hoInput
Procedure_Return
End
Get ComAddQueryParam Of hoRest "comp" "blocklist" To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Send ComFileClose To hoInput
Procedure_Return
End
Get ComAddQueryParam Of hoRest "blocklisttype" "uncommitted" To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Send ComFileClose To hoInput
Procedure_Return
End
Get ComDisconnect Of hoRest 10 To iSuccess
Get ComGetAsString Of hoEndpoint To sTemp1
Get ComConnect Of hoConnection sTemp1 443 True 20000 To iSuccess
If (iSuccess <> True) Begin
Showln "TLS reconnection failed."
Send ComFileClose To hoInput
Procedure_Return
End
Get pvComObject of hoConnection to vConnection
Get ComUseConnection Of hoRest vConnection False To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Send ComFileClose To hoInput
Procedure_Return
End
Get ComFullRequestNoBody Of hoRest "GET" sResourcePath To sResponseText
Get ComLastMethodSuccess Of hoRest To bTemp1
If (bTemp1 <> True) Begin
Showln "Could not reconcile uploaded blocks."
Send ComFileClose To hoInput
Procedure_Return
End
Get Create (RefClass(cComChilkatHashtable)) To hoRemoteBlocks
If (Not(IsComObjectCreated(hoRemoteBlocks))) Begin
Send CreateComObject of hoRemoteBlocks
End
Get ComResponseStatusCode Of hoRest To iTemp1
If (iTemp1 = 200) Begin
Get ComLoadXml Of hoResult sResponseText To iSuccess
If (iSuccess <> True) Begin
Showln "Expected well-formed XML."
Send ComFileClose To hoInput
Procedure_Return
End
Get ComTagEquals Of hoResult "BlockList" To bTemp1
If (bTemp1 <> True) Begin
Showln "Unexpected XML response root."
Send ComFileClose To hoInput
Procedure_Return
End
Get ComNumChildrenAt Of hoResult "UncommittedBlocks" To iRemoteCount
Move 0 To j
While (j < iRemoteCount)
Set ComI Of hoResult To j
Get ComGetChildContent Of hoResult "UncommittedBlocks|Block[i]|Name" To sRemoteId
Get ComGetChildContent Of hoResult "UncommittedBlocks|Block[i]|Size" To sRemoteSize
Send ComClear To hoTextCompare
Get ComSetString Of hoTextCompare sRemoteId To iSuccess
Get ComContentsEqual Of hoTextCompare "" True To iSameText11
Send ComClear To hoTextCompare
Get ComSetString Of hoTextCompare sRemoteSize To iSuccess
Get ComContentsEqual Of hoTextCompare "" True To iSameText12
If ((iSameText11 = True) Or (iSameText12 = True)) Begin
Showln "Malformed remote block listing."
Send ComFileClose To hoInput
Procedure_Return
End
Get ComAddStr Of hoRemoteBlocks sRemoteId sRemoteSize To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Send ComFileClose To hoInput
Procedure_Return
End
Move (j + 1) To j
Loop
End
Else Begin
Send ComClear To hoTextCompare
Get ComResponseHdrByName Of hoRest "x-ms-error-code" To sTemp1
Get ComSetString Of hoTextCompare sTemp1 To iSuccess
Get ComContentsEqual Of hoTextCompare "BlobNotFound" True To iSameText13
Get ComResponseStatusCode Of hoRest To iTemp1
If ((iTemp1 <> 404) Or (iSameText13 <> True)) Begin
Showln "Block listing failed."
Send ComFileClose To hoInput
Procedure_Return
End
End
Get Create (RefClass(cComChilkatXml)) To hoBlocks
If (Not(IsComObjectCreated(hoBlocks))) Begin
Send CreateComObject of hoBlocks
End
Set ComTag Of hoBlocks To "BlockList"
Get Create (RefClass(cComChilkatBinData)) To hoChunk
If (Not(IsComObjectCreated(hoChunk))) Begin
Send CreateComObject of hoChunk
End
Get Create (RefClass(cComChilkatStringBuilder)) To hoBlockText
If (Not(IsComObjectCreated(hoBlockText))) Begin
Send CreateComObject of hoBlockText
End
Get Create (RefClass(cComChilkatStringBuilder)) To hoSizeText
If (Not(IsComObjectCreated(hoSizeText))) Begin
Send CreateComObject of hoSizeText
End
Move 0 To i
While (i < iNumBlocks)
Get ComClear Of hoChunk To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Send ComFileClose To hoInput
Procedure_Return
End
Get pvComObject of hoChunk to vChunk
Get ComReadBlockBd Of hoInput i iBlockSize vChunk To iSuccess
If (iSuccess <> True) Begin
Showln "Could not read source block."
Send ComFileClose To hoInput
Procedure_Return
End
Get ComNumBytes Of hoChunk To iTemp1
Get ComNumBytes Of hoChunk To iTemp2
If ((iTemp1 < 1) Or ((i < iNumBlocks - 1) And (iTemp2 <> iBlockSize))) Begin
Showln "Source changed or an incomplete read occurred."
Send ComFileClose To hoInput
Procedure_Return
End
Send ComClear To hoBlockText
Get ComAppend Of hoBlockText sUploadId To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Send ComFileClose To hoInput
Procedure_Return
End
Get ComGenBlockId Of hoInput i 5 "ascii" To sTemp1
Get ComAppend Of hoBlockText sTemp1 To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Send ComFileClose To hoInput
Procedure_Return
End
Get ComEncode Of hoBlockText "base64" "utf-8" To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Send ComFileClose To hoInput
Procedure_Return
End
Get ComGetAsString Of hoBlockText To sBlockId
Send ComClear To hoSizeText
Get ComNumBytes Of hoChunk To iTemp1
Get ComAppendInt Of hoSizeText iTemp1 To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Send ComFileClose To hoInput
Procedure_Return
End
Move True To iUploadBlock
Get ComContains Of hoRemoteBlocks sBlockId To bTemp1
If (bTemp1 = True) Begin
Get ComLookupStr Of hoRemoteBlocks sBlockId To sTemp1
Get ComGetAsString Of hoSizeText To sTemp2
If (sTemp1 <> sTemp2) Begin
Showln "Remote block size differs; do not commit this upload."
Send ComFileClose To hoInput
Procedure_Return
End
Move False To iUploadBlock
End
If (iUploadBlock = True) Begin
Get ComClearAllQueryParams Of hoRest To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Send ComFileClose To hoInput
Procedure_Return
End
Get ComAddQueryParam Of hoRest "comp" "block" To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Send ComFileClose To hoInput
Procedure_Return
End
Get ComAddQueryParam Of hoRest "blockid" sBlockId To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Send ComFileClose To hoInput
Procedure_Return
End
Get ComDisconnect Of hoRest 10 To iSuccess
Get ComGetAsString Of hoEndpoint To sTemp1
Get ComConnect Of hoConnection sTemp1 443 True 20000 To iSuccess
If (iSuccess <> True) Begin
Showln "TLS reconnection failed."
Send ComFileClose To hoInput
Procedure_Return
End
Get pvComObject of hoConnection to vConnection
Get ComUseConnection Of hoRest vConnection False To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Send ComFileClose To hoInput
Procedure_Return
End
Send ComClear To hoResponseBody
Get pvComObject of hoChunk to vChunk
Get pvComObject of hoResponseBody to vResponseBody
Get ComFullRequestBd Of hoRest "PUT" sResourcePath vChunk vResponseBody To iSuccess
If (iSuccess <> True) Begin
Showln "Request did not complete; outcome may be uncertain."
Send ComFileClose To hoInput
Procedure_Return
End
Get ComResponseStatusCode Of hoRest To iTemp1
If (iTemp1 <> 201) Begin
Get ComResponseStatusCode Of hoRest To iTemp1
Showln "HTTP status: " iTemp1
Get ComResponseHdrByName Of hoRest "x-ms-error-code" To sTemp1
Showln "Azure error code: " sTemp1
Get ComResponseHdrByName Of hoRest "x-ms-request-id" To sTemp1
Showln "Request ID: " sTemp1
// Inspect any error body privately; do not log credentials, SAS URLs or payloads.
Send ComFileClose To hoInput
Procedure_Return
End
End
Send ComNewChild2 To hoBlocks "Uncommitted" sBlockId
Move (i + 1) To i
Loop
// Rehash before commit. Do not modify the source or run concurrent writers.
Get ComHashFileENC Of hoHash sSourceFile To sFinalFingerprint
Send ComClear To hoTextCompare
Get ComSetString Of hoTextCompare sFinalFingerprint To iSuccess
Get ComContentsEqual Of hoTextCompare sFingerprint True To iSameText14
Get ComLastMethodSuccess Of hoHash To bTemp1
If ((bTemp1 <> True) Or (iSameText14 <> True)) Begin
Showln "Source changed during staging; commit cancelled."
Send ComFileClose To hoInput
Procedure_Return
End
Send ComFileClose To hoInput
Get ComClearAllQueryParams Of hoRest To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
Get ComAddQueryParam Of hoRest "comp" "blocklist" To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
Get ComAddHeader Of hoRest "Content-Type" "application/xml" To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
Get ComAddHeader Of hoRest "x-ms-blob-content-type" "application/octet-stream" To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
Get ComAddHeader Of hoRest "If-None-Match" "*" To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
Get ComAddHeader Of hoRest "x-ms-meta-upload-id" sUploadId To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
Get ComAddHeader Of hoRest "x-ms-meta-source-sha256" sFingerprint To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
Get ComDisconnect Of hoRest 10 To iSuccess
Get ComGetAsString Of hoEndpoint To sTemp1
Get ComConnect Of hoConnection sTemp1 443 True 20000 To iSuccess
If (iSuccess <> True) Begin
Showln "TLS reconnection failed."
Procedure_Return
End
Get pvComObject of hoConnection to vConnection
Get ComUseConnection Of hoRest vConnection False To iSuccess
If (iSuccess <> True) Begin
Showln "Could not prepare the request."
Procedure_Return
End
Get ComGetXml Of hoBlocks To sTemp1
Get ComFullRequestString Of hoRest "PUT" sResourcePath sTemp1 To sResponseText
Get ComLastMethodSuccess Of hoRest To bTemp1
If (bTemp1 <> True) Begin
Showln "Request did not complete; outcome may be uncertain."
Procedure_Return
End
Get ComResponseStatusCode Of hoRest To iTemp1
If (iTemp1 <> 201) Begin
Get ComResponseStatusCode Of hoRest To iTemp1
Showln "HTTP status: " iTemp1
Get ComResponseHdrByName Of hoRest "x-ms-error-code" To sTemp1
Showln "Azure error code: " sTemp1
Get ComResponseHdrByName Of hoRest "x-ms-request-id" To sTemp1
Showln "Request ID: " sTemp1
// Inspect any error body privately; do not log credentials, SAS URLs or payloads.
Procedure_Return
End
Showln "Upload committed. Retain the checkpoint for reconciliation until completion is recorded."
End_Procedure