Sample code for 30+ languages & platforms
Visual FoxPro Requires Chilkat v11.6.0+

Amazon S3: Retrieve Checksum Metadata and Verify a Download

See more S3 - REST Examples

Use GetObjectAttributes to retrieve checksum metadata, ETag and size. For an object with a FULL_OBJECT SHA-256 checksum, download with checksum-mode=ENABLED, pin its version when available, apply If-Match, and compare the downloaded file’s base64 SHA-256 and length. The full object is streamed rather than held in memory.

This example deliberately verifies SHA-256 only. Upload with x-amz-checksum-sha256 to create an appropriate single-PUT object. An automatically assigned CRC64NVME checksum or a COMPOSITE multipart checksum requires a different calculation; the example reports unsupported metadata and stops. Never compare a composite checksum or an ETag with the ordinary whole-file SHA-256. Requires GetObject/GetObjectAttributes permissions (and version-specific equivalents when used), with additional KMS permissions for encrypted checksums/reads.

For general purpose S3 buckets, using regional HTTPS endpoints and AWS Signature Version 4. Directory buckets (S3 Express), access points, Outposts, and other AWS partitions need their own endpoint/authentication rules. Use a bucket name without dots for these virtual-hosted TLS examples; see the path-style example for dotted names.

Provide current IAM credentials in a private qa_data/aws/s3.json file with string fields access_key, secret_key, and session_token for temporary credentials. Prefer short-lived role credentials. This file is explicitly loaded; these examples do not discover profiles or refresh credentials. Keep it outside public content and source control. The session token is included in the signed request. TLS certificate verification is enabled on the Socket used by Rest.

Transport success and HTTP success are different. Keep full diagnostics private; signed requests and presigned URLs can contain credentials or grant access. For retryable reads use bounded backoff with jitter. Before retrying a write with an uncertain outcome, check the resource state. Keep keys, upload IDs, version IDs, ETags, and large sizes as strings.

AWS GetObjectAttributes reference

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loTextCompare
LOCAL loCredentials
LOCAL lnSameText1
LOCAL lnSameText2
LOCAL lcRegion
LOCAL lcBucketName
LOCAL loEndpoint
LOCAL loAws
LOCAL loRest
LOCAL lnSameText3
LOCAL loConnection
LOCAL loXml
LOCAL lcObjectKey
LOCAL loObjectPath
LOCAL lnRestoredSlashes
LOCAL lcResponseBody
LOCAL lnSameText4
LOCAL lnSameText5
LOCAL lnSameText6
LOCAL lnSameText7
LOCAL lnSameText8
LOCAL lnSameText9
LOCAL lcExpectedChecksum
LOCAL lcExpectedSize
LOCAL loEtag
LOCAL lcVersionId
LOCAL lnSameText10
LOCAL loFiles
LOCAL lnStatusCode
LOCAL lcErrorBody
LOCAL lnSameText11
LOCAL lcResponseChecksum
LOCAL lnSameText12
LOCAL lnSameText13
LOCAL loOutput
LOCAL lcActualSize
LOCAL lnSameText14
LOCAL loDigest
LOCAL lcActualChecksum
LOCAL lnSameText15

lnSuccess = 0

*  StringBuilder compares text by value in every generated language.
loTextCompare = CreateObject('Chilkat.StringBuilder')
*  Assumes Chilkat is unlocked. See Global Unlock Sample.
lnSuccess = 0
*  Private configuration, not a file in public web content or source control.
*  Load current IAM credentials authorized for the S3 operation.
loCredentials = CreateObject('Chilkat.JsonObject')
loCredentials.Strict = 1
lnSuccess = loCredentials.LoadFile("qa_data/aws/s3.json")
IF (lnSuccess <> 1) THEN
    ? "Could not load private AWS credentials."
    RELEASE loTextCompare
    RELEASE loCredentials
    CANCEL
ENDIF

loTextCompare.Clear()
loTextCompare.SetString(loCredentials.StringOf("access_key"))
lnSameText1 = loTextCompare.ContentsEqual("",1)
IF ((loCredentials.JsonTypeOf("access_key") <> 1) OR (lnSameText1 = 1)) THEN
    ? "Missing or invalid access_key."
    RELEASE loTextCompare
    RELEASE loCredentials
    CANCEL
ENDIF

loTextCompare.Clear()
loTextCompare.SetString(loCredentials.StringOf("secret_key"))
lnSameText2 = loTextCompare.ContentsEqual("",1)
IF ((loCredentials.JsonTypeOf("secret_key") <> 1) OR (lnSameText2 = 1)) THEN
    ? "Missing or invalid secret_key."
    RELEASE loTextCompare
    RELEASE loCredentials
    CANCEL
ENDIF

*  General purpose bucket in the commercial AWS partition.
lcRegion = "us-west-2"
lcBucketName = "amzn-s3-demo-bucket"
loEndpoint = CreateObject('Chilkat.StringBuilder')
lnSuccess = loEndpoint.Append(lcBucketName)
IF (lnSuccess <> 1) THEN
    ? "Could not build text."
    RELEASE loTextCompare
    RELEASE loCredentials
    RELEASE loEndpoint
    CANCEL
ENDIF

lnSuccess = loEndpoint.Append(".")
IF (lnSuccess <> 1) THEN
    ? "Could not build text."
    RELEASE loTextCompare
    RELEASE loCredentials
    RELEASE loEndpoint
    CANCEL
ENDIF

lnSuccess = loEndpoint.Append("s3.")
IF (lnSuccess <> 1) THEN
    ? "Could not build text."
    RELEASE loTextCompare
    RELEASE loCredentials
    RELEASE loEndpoint
    CANCEL
ENDIF

lnSuccess = loEndpoint.Append(lcRegion)
IF (lnSuccess <> 1) THEN
    ? "Could not build text."
    RELEASE loTextCompare
    RELEASE loCredentials
    RELEASE loEndpoint
    CANCEL
ENDIF

lnSuccess = loEndpoint.Append(".amazonaws.com")
IF (lnSuccess <> 1) THEN
    ? "Could not build text."
    RELEASE loTextCompare
    RELEASE loCredentials
    RELEASE loEndpoint
    CANCEL
ENDIF

loAws = CreateObject('Chilkat.AuthAws')
loAws.AccessKey = loCredentials.StringOf("access_key")
loAws.SecretKey = loCredentials.StringOf("secret_key")
loAws.Region = lcRegion
loAws.ServiceName = "s3"
loAws.SignatureVersion = 4
loRest = CreateObject('Chilkat.Rest')
loRest.ConnectTimeoutMs = 20000
loRest.IdleTimeoutMs = 60000
lnSuccess = loRest.SetAuthAws(loAws)
IF (lnSuccess <> 1) THEN
    ? "Could not configure AWS signing."
    RELEASE loTextCompare
    RELEASE loCredentials
    RELEASE loEndpoint
    RELEASE loAws
    RELEASE loRest
    CANCEL
ENDIF

*  Temporary credentials require this token in every signed query.
*  Keep request URLs private. Do not clear this parameter between requests.
IF (loCredentials.HasMember("session_token") = 1) THEN
    IF (loCredentials.JsonTypeOf("session_token") <> 1) THEN
        ? "session_token must be a string."
        RELEASE loTextCompare
        RELEASE loCredentials
        RELEASE loEndpoint
        RELEASE loAws
        RELEASE loRest
        CANCEL
    ENDIF

    loTextCompare.Clear()
    loTextCompare.SetString(loCredentials.StringOf("session_token"))
    lnSameText3 = loTextCompare.ContentsEqual("",1)
    IF (lnSameText3 <> 1) THEN
        lnSuccess = loRest.AddQueryParam("X-Amz-Security-Token",loCredentials.StringOf("session_token"))
        IF (lnSuccess <> 1) THEN
            ? "Could not prepare the request."
            RELEASE loTextCompare
            RELEASE loCredentials
            RELEASE loEndpoint
            RELEASE loAws
            RELEASE loRest
            CANCEL
        ENDIF

    ENDIF

ENDIF

*  Connect to the SAME hostname used for TLS verification and request signing.
loConnection = CreateObject('Chilkat.Socket')
loConnection.RequireSslCertVerify = 1
loConnection.MaxReadIdleMs = 60000
loConnection.MaxSendIdleMs = 60000
lnSuccess = loConnection.Connect(loEndpoint.GetAsString(),443,1,20000)
IF (lnSuccess <> 1) THEN
    ? "TLS connection failed; inspect diagnostics privately."
    RELEASE loTextCompare
    RELEASE loCredentials
    RELEASE loEndpoint
    RELEASE loAws
    RELEASE loRest
    RELEASE loConnection
    CANCEL
ENDIF

lnSuccess = loRest.UseConnection(loConnection,1)
IF (lnSuccess <> 1) THEN
    ? "Could not attach the TLS connection."
    RELEASE loTextCompare
    RELEASE loCredentials
    RELEASE loEndpoint
    RELEASE loAws
    RELEASE loRest
    RELEASE loConnection
    CANCEL
ENDIF

loXml = CreateObject('Chilkat.Xml')
loXml.Strict = 1
*  Supply an unencoded object key, not a URL. Preserve slashes in the key.
lcObjectKey = "documents/example.txt"
loObjectPath = CreateObject('Chilkat.StringBuilder')
lnSuccess = loObjectPath.Append(lcObjectKey)
IF (lnSuccess <> 1) THEN
    ? "Could not build text."
    RELEASE loTextCompare
    RELEASE loCredentials
    RELEASE loEndpoint
    RELEASE loAws
    RELEASE loRest
    RELEASE loConnection
    RELEASE loXml
    RELEASE loObjectPath
    CANCEL
ENDIF

lnSuccess = loObjectPath.Encode("url_rfc3986","utf-8")
IF (lnSuccess <> 1) THEN
    ? "Could not encode the object key."
    RELEASE loTextCompare
    RELEASE loCredentials
    RELEASE loEndpoint
    RELEASE loAws
    RELEASE loRest
    RELEASE loConnection
    RELEASE loXml
    RELEASE loObjectPath
    CANCEL
ENDIF

lnRestoredSlashes = loObjectPath.Replace("%2F","/")
lnSuccess = loObjectPath.Prepend("/")
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loCredentials
    RELEASE loEndpoint
    RELEASE loAws
    RELEASE loRest
    RELEASE loConnection
    RELEASE loXml
    RELEASE loObjectPath
    CANCEL
ENDIF

lnSuccess = loRest.AddQueryParam("attributes","")
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loCredentials
    RELEASE loEndpoint
    RELEASE loAws
    RELEASE loRest
    RELEASE loConnection
    RELEASE loXml
    RELEASE loObjectPath
    CANCEL
ENDIF

lnSuccess = loRest.AddHeader("x-amz-object-attributes","ETag,Checksum,ObjectSize")
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loCredentials
    RELEASE loEndpoint
    RELEASE loAws
    RELEASE loRest
    RELEASE loConnection
    RELEASE loXml
    RELEASE loObjectPath
    CANCEL
ENDIF

lcResponseBody = loRest.FullRequestNoBody("GET",loObjectPath.GetAsString())
IF (loRest.LastMethodSuccess <> 1) THEN
    ? "Request did not complete; inspect diagnostics privately."
    RELEASE loTextCompare
    RELEASE loCredentials
    RELEASE loEndpoint
    RELEASE loAws
    RELEASE loRest
    RELEASE loConnection
    RELEASE loXml
    RELEASE loObjectPath
    CANCEL
ENDIF

IF (loRest.ResponseStatusCode <> 200) THEN
    ? "S3 HTTP status: " + STR(loRest.ResponseStatusCode)
    lnSuccess = loXml.LoadXml(lcResponseBody)
    loTextCompare.Clear()
    loTextCompare.SetString(loXml.Tag)
    lnSameText4 = loTextCompare.ContentsEqual("Error",1)
    IF ((lnSuccess = 1) AND (lnSameText4 = 1)) THEN
        ? "S3 error code: " + loXml.GetChildContent("Code")
    ENDIF

    *  Keep signed headers, credentials, URLs, and full diagnostics private.
    *  A timeout may leave a write's outcome uncertain. Check before retrying.
    RELEASE loTextCompare
    RELEASE loCredentials
    RELEASE loEndpoint
    RELEASE loAws
    RELEASE loRest
    RELEASE loConnection
    RELEASE loXml
    RELEASE loObjectPath
    CANCEL
ENDIF

lnSuccess = loXml.LoadXml(lcResponseBody)
IF (lnSuccess <> 1) THEN
    ? "Expected well-formed XML."
    RELEASE loTextCompare
    RELEASE loCredentials
    RELEASE loEndpoint
    RELEASE loAws
    RELEASE loRest
    RELEASE loConnection
    RELEASE loXml
    RELEASE loObjectPath
    CANCEL
ENDIF

loTextCompare.Clear()
loTextCompare.SetString(loXml.Tag)
lnSameText5 = loTextCompare.ContentsEqual("GetObjectAttributesResponse",1)
IF (lnSameText5 <> 1) THEN
    ? "Unexpected S3 response element; this is not a successful result."
    RELEASE loTextCompare
    RELEASE loCredentials
    RELEASE loEndpoint
    RELEASE loAws
    RELEASE loRest
    RELEASE loConnection
    RELEASE loXml
    RELEASE loObjectPath
    CANCEL
ENDIF

loTextCompare.Clear()
loTextCompare.SetString(loXml.GetChildContent("ETag"))
lnSameText6 = loTextCompare.ContentsEqual("",1)
IF ((loXml.HasChildWithTag("ETag") <> 1) OR (lnSameText6 = 1)) THEN
    ? "Missing response field: ETag"
    RELEASE loTextCompare
    RELEASE loCredentials
    RELEASE loEndpoint
    RELEASE loAws
    RELEASE loRest
    RELEASE loConnection
    RELEASE loXml
    RELEASE loObjectPath
    CANCEL
ENDIF

loTextCompare.Clear()
loTextCompare.SetString(loXml.GetChildContent("ObjectSize"))
lnSameText7 = loTextCompare.ContentsEqual("",1)
IF ((loXml.HasChildWithTag("ObjectSize") <> 1) OR (lnSameText7 = 1)) THEN
    ? "Missing response field: ObjectSize"
    RELEASE loTextCompare
    RELEASE loCredentials
    RELEASE loEndpoint
    RELEASE loAws
    RELEASE loRest
    RELEASE loConnection
    RELEASE loXml
    RELEASE loObjectPath
    CANCEL
ENDIF

? "Object size: " + loXml.GetChildContent("ObjectSize")
? "Checksum metadata: " + loXml.GetChildContent("Checksum|ChecksumType")
loTextCompare.Clear()
loTextCompare.SetString(loXml.GetChildContent("Checksum|ChecksumType"))
lnSameText8 = loTextCompare.ContentsEqual("FULL_OBJECT",1)
IF ((lnSameText8 <> 1) OR (loXml.HasChildWithTag("Checksum|ChecksumSHA256") <> 1)) THEN
    ? "This verifier requires a full-object SHA-256 checksum; no download or verification was performed."
    RELEASE loTextCompare
    RELEASE loCredentials
    RELEASE loEndpoint
    RELEASE loAws
    RELEASE loRest
    RELEASE loConnection
    RELEASE loXml
    RELEASE loObjectPath
    CANCEL
ENDIF

loTextCompare.Clear()
loTextCompare.SetString(loXml.GetChildContent("Checksum|ChecksumSHA256"))
lnSameText9 = loTextCompare.ContentsEqual("",1)
IF ((loXml.HasChildWithTag("Checksum|ChecksumSHA256") <> 1) OR (lnSameText9 = 1)) THEN
    ? "Missing response field: Checksum|ChecksumSHA256"
    RELEASE loTextCompare
    RELEASE loCredentials
    RELEASE loEndpoint
    RELEASE loAws
    RELEASE loRest
    RELEASE loConnection
    RELEASE loXml
    RELEASE loObjectPath
    CANCEL
ENDIF

lcExpectedChecksum = loXml.GetChildContent("Checksum|ChecksumSHA256")
lcExpectedSize = loXml.GetChildContent("ObjectSize")
loEtag = CreateObject('Chilkat.StringBuilder')
lnSuccess = loEtag.Append(loXml.GetChildContent("ETag"))
IF (lnSuccess <> 1) THEN
    ? "Could not build text."
    RELEASE loTextCompare
    RELEASE loCredentials
    RELEASE loEndpoint
    RELEASE loAws
    RELEASE loRest
    RELEASE loConnection
    RELEASE loXml
    RELEASE loObjectPath
    RELEASE loEtag
    CANCEL
ENDIF

IF (loEtag.StartsWith('"',1) <> 1) THEN
    lnSuccess = loEtag.Prepend('"')
    IF (lnSuccess <> 1) THEN
        ? "Could not prepare the request."
        RELEASE loTextCompare
        RELEASE loCredentials
        RELEASE loEndpoint
        RELEASE loAws
        RELEASE loRest
        RELEASE loConnection
        RELEASE loXml
        RELEASE loObjectPath
        RELEASE loEtag
        CANCEL
    ENDIF

    lnSuccess = loEtag.Append('"')
    IF (lnSuccess <> 1) THEN
        ? "Could not build text."
        RELEASE loTextCompare
        RELEASE loCredentials
        RELEASE loEndpoint
        RELEASE loAws
        RELEASE loRest
        RELEASE loConnection
        RELEASE loXml
        RELEASE loObjectPath
        RELEASE loEtag
        CANCEL
    ENDIF

ENDIF

lcVersionId = loRest.ResponseHdrByName("x-amz-version-id")
IF (loRest.LastMethodSuccess <> 1) THEN
    lcVersionId = ""
ENDIF

lnSuccess = loRest.RemoveQueryParam("attributes")
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loCredentials
    RELEASE loEndpoint
    RELEASE loAws
    RELEASE loRest
    RELEASE loConnection
    RELEASE loXml
    RELEASE loObjectPath
    RELEASE loEtag
    CANCEL
ENDIF

lnSuccess = loRest.RemoveHeader("x-amz-object-attributes")
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loCredentials
    RELEASE loEndpoint
    RELEASE loAws
    RELEASE loRest
    RELEASE loConnection
    RELEASE loXml
    RELEASE loObjectPath
    RELEASE loEtag
    CANCEL
ENDIF

loTextCompare.Clear()
loTextCompare.SetString(lcVersionId)
lnSameText10 = loTextCompare.ContentsEqual("",1)
IF (lnSameText10 <> 1) THEN
    lnSuccess = loRest.AddQueryParam("versionId",lcVersionId)
    IF (lnSuccess <> 1) THEN
        ? "Could not prepare the request."
        RELEASE loTextCompare
        RELEASE loCredentials
        RELEASE loEndpoint
        RELEASE loAws
        RELEASE loRest
        RELEASE loConnection
        RELEASE loXml
        RELEASE loObjectPath
        RELEASE loEtag
        CANCEL
    ENDIF

ENDIF

lnSuccess = loRest.AddHeader("If-Match",loEtag.GetAsString())
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loCredentials
    RELEASE loEndpoint
    RELEASE loAws
    RELEASE loRest
    RELEASE loConnection
    RELEASE loXml
    RELEASE loObjectPath
    RELEASE loEtag
    CANCEL
ENDIF

lnSuccess = loRest.AddHeader("x-amz-checksum-mode","ENABLED")
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loCredentials
    RELEASE loEndpoint
    RELEASE loAws
    RELEASE loRest
    RELEASE loConnection
    RELEASE loXml
    RELEASE loObjectPath
    RELEASE loEtag
    CANCEL
ENDIF

loFiles = CreateObject('Chilkat.FileAccess')
IF (loFiles.FileExists("s3-checksum-download.part") = 1) THEN
    ? "Choose a new staging path."
    RELEASE loTextCompare
    RELEASE loCredentials
    RELEASE loEndpoint
    RELEASE loAws
    RELEASE loRest
    RELEASE loConnection
    RELEASE loXml
    RELEASE loObjectPath
    RELEASE loEtag
    RELEASE loFiles
    CANCEL
ENDIF

lnSuccess = loRest.SendReqNoBody("GET",loObjectPath.GetAsString())
IF (lnSuccess <> 1) THEN
    ? "Could not send download request."
    RELEASE loTextCompare
    RELEASE loCredentials
    RELEASE loEndpoint
    RELEASE loAws
    RELEASE loRest
    RELEASE loConnection
    RELEASE loXml
    RELEASE loObjectPath
    RELEASE loEtag
    RELEASE loFiles
    CANCEL
ENDIF

lnStatusCode = loRest.ReadResponseHeader()
IF (lnStatusCode < 0) THEN
    ? "Could not read download headers."
    RELEASE loTextCompare
    RELEASE loCredentials
    RELEASE loEndpoint
    RELEASE loAws
    RELEASE loRest
    RELEASE loConnection
    RELEASE loXml
    RELEASE loObjectPath
    RELEASE loEtag
    RELEASE loFiles
    CANCEL
ENDIF

IF (lnStatusCode <> 200) THEN
    ? "Download HTTP status: " + STR(lnStatusCode)
    lcErrorBody = loRest.ReadRespBodyString()
    IF (loRest.LastMethodSuccess = 1) THEN
        lnSuccess = loXml.LoadXml(lcErrorBody)
        loTextCompare.Clear()
        loTextCompare.SetString(loXml.Tag)
        lnSameText11 = loTextCompare.ContentsEqual("Error",1)
        IF ((lnSuccess = 1) AND (lnSameText11 = 1)) THEN
            ? "S3 error code: " + loXml.GetChildContent("Code")
        ENDIF

    ENDIF

    RELEASE loTextCompare
    RELEASE loCredentials
    RELEASE loEndpoint
    RELEASE loAws
    RELEASE loRest
    RELEASE loConnection
    RELEASE loXml
    RELEASE loObjectPath
    RELEASE loEtag
    RELEASE loFiles
    CANCEL
ENDIF

lcResponseChecksum = loRest.ResponseHdrByName("x-amz-checksum-sha256")
loTextCompare.Clear()
loTextCompare.SetString(lcResponseChecksum)
lnSameText12 = loTextCompare.ContentsEqual("",1)
IF ((loRest.LastMethodSuccess <> 1) OR (lnSameText12 = 1)) THEN
    ? "Missing response header: x-amz-checksum-sha256"
    RELEASE loTextCompare
    RELEASE loCredentials
    RELEASE loEndpoint
    RELEASE loAws
    RELEASE loRest
    RELEASE loConnection
    RELEASE loXml
    RELEASE loObjectPath
    RELEASE loEtag
    RELEASE loFiles
    CANCEL
ENDIF

loTextCompare.Clear()
loTextCompare.SetString(lcResponseChecksum)
lnSameText13 = loTextCompare.ContentsEqual(lcExpectedChecksum,1)
IF (lnSameText13 <> 1) THEN
    ? "Checksum changed between metadata and download."
    RELEASE loTextCompare
    RELEASE loCredentials
    RELEASE loEndpoint
    RELEASE loAws
    RELEASE loRest
    RELEASE loConnection
    RELEASE loXml
    RELEASE loObjectPath
    RELEASE loEtag
    RELEASE loFiles
    CANCEL
ENDIF

loOutput = CreateObject('Chilkat.Stream')
loOutput.SinkFile = "s3-checksum-download.part"
lnSuccess = loRest.ReadRespBodyStream(loOutput,1)
IF (lnSuccess <> 1) THEN
    ? "Download incomplete; partial output is not verified."
    RELEASE loTextCompare
    RELEASE loCredentials
    RELEASE loEndpoint
    RELEASE loAws
    RELEASE loRest
    RELEASE loConnection
    RELEASE loXml
    RELEASE loObjectPath
    RELEASE loEtag
    RELEASE loFiles
    RELEASE loOutput
    CANCEL
ENDIF

lcActualSize = loFiles.FileSizeStr("s3-checksum-download.part")
loTextCompare.Clear()
loTextCompare.SetString(lcActualSize)
lnSameText14 = loTextCompare.ContentsEqual(lcExpectedSize,1)
IF ((loFiles.LastMethodSuccess <> 1) OR (lnSameText14 <> 1)) THEN
    ? "Downloaded size mismatch."
    RELEASE loTextCompare
    RELEASE loCredentials
    RELEASE loEndpoint
    RELEASE loAws
    RELEASE loRest
    RELEASE loConnection
    RELEASE loXml
    RELEASE loObjectPath
    RELEASE loEtag
    RELEASE loFiles
    RELEASE loOutput
    CANCEL
ENDIF

loDigest = CreateObject('Chilkat.Crypt2')
loDigest.HashAlgorithm = "sha256"
loDigest.EncodingMode = "base64"
lcActualChecksum = loDigest.HashFileENC("s3-checksum-download.part")
loTextCompare.Clear()
loTextCompare.SetString(lcActualChecksum)
lnSameText15 = loTextCompare.ContentsEqual(lcExpectedChecksum,1)
IF ((loDigest.LastMethodSuccess <> 1) OR (lnSameText15 <> 1)) THEN
    ? "SHA-256 mismatch; do not publish the staged file."
    RELEASE loTextCompare
    RELEASE loCredentials
    RELEASE loEndpoint
    RELEASE loAws
    RELEASE loRest
    RELEASE loConnection
    RELEASE loXml
    RELEASE loObjectPath
    RELEASE loEtag
    RELEASE loFiles
    RELEASE loOutput
    RELEASE loDigest
    CANCEL
ENDIF

? "Downloaded object verified using its full-object SHA-256 checksum."

RELEASE loTextCompare
RELEASE loCredentials
RELEASE loEndpoint
RELEASE loAws
RELEASE loRest
RELEASE loConnection
RELEASE loXml
RELEASE loObjectPath
RELEASE loEtag
RELEASE loFiles
RELEASE loOutput
RELEASE loDigest