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

Amazon S3: Upload Multipart Parts and Record ETags

See more S3 - REST Examples

Upload an unchanged file in 8 MiB parts and record each exact ETag in ascending part-number order. Requires s3:PutObject. All parts except the last must be at least 5 MiB; use no more than 10,000 parts and choose a larger part size for larger files. This demonstration buffers at most one part for signing rather than the whole file.

Restarting uploads every part again for the same upload ID. It intentionally does not claim durable resumability from a stale local list. Do not run simultaneous writers or change the input file. Prior completion data is invalidated before upload, and a new completion body is saved only after all parts succeed. To implement selective resume, bind state to a file fingerprint and reconcile server parts.

Part of the initiate / upload parts / complete workflow. State in s3-multipart.json binds the upload ID to its bucket, region and key. Keep it private. Incomplete parts incur storage charges until completed or aborted; configure an AbortIncompleteMultipartUpload lifecycle rule as cleanup protection. These examples use the default checksum behavior without selecting a separate composite checksum algorithm. If you choose one at initiation, store each required part checksum and supply it at completion.

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 UploadPart reference

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
long li_Success
oleobject loo_TextCompare
oleobject loo_Credentials
long li_SameText1
long li_SameText2
string ls_Region
string ls_BucketName
oleobject loo_Endpoint
oleobject loo_Aws
oleobject loo_Rest
long li_SameText3
oleobject loo_Connection
oleobject loo_Xml
oleobject loo_State
long li_SameText4
long li_SameText5
long li_SameText6
long li_SameText7
long li_SameText8
long li_SameText9
string ls_UploadId
string ls_ObjectKey
oleobject loo_ObjectPath
long li_RestoredSlashes
string ls_InputFile
long li_PartSize
oleobject loo_Files
long li_NumParts
oleobject loo_Parts
oleobject loo_PartNumberText
long li_PartNumber
oleobject loo_Part
oleobject loo_PartResponse
string ls_ResponseBody
long li_SameText10
string ls_Etag
long li_SameText11

li_Success = 0

//  StringBuilder compares text by value in every generated language.
loo_TextCompare = create oleobject
li_rc = loo_TextCompare.ConnectToNewObject("Chilkat.StringBuilder")
if li_rc < 0 then
    destroy loo_TextCompare
    MessageBox("Error","Connecting to COM object failed")
    return
end if
//  Assumes Chilkat is unlocked. See Global Unlock Sample.
li_Success = 0
//  Private configuration, not a file in public web content or source control.
//  Load current IAM credentials authorized for the S3 operation.
loo_Credentials = create oleobject
li_rc = loo_Credentials.ConnectToNewObject("Chilkat.JsonObject")

loo_Credentials.Strict = 1
li_Success = loo_Credentials.LoadFile("qa_data/aws/s3.json")
if li_Success <> 1 then
    Write-Debug "Could not load private AWS credentials."
    destroy loo_TextCompare
    destroy loo_Credentials
    return
end if

loo_TextCompare.Clear()
loo_TextCompare.SetString(loo_Credentials.StringOf("access_key"))
li_SameText1 = loo_TextCompare.ContentsEqual("",1)
if (loo_Credentials.JsonTypeOf("access_key") <> 1) OR (li_SameText1 = 1) then
    Write-Debug "Missing or invalid access_key."
    destroy loo_TextCompare
    destroy loo_Credentials
    return
end if

loo_TextCompare.Clear()
loo_TextCompare.SetString(loo_Credentials.StringOf("secret_key"))
li_SameText2 = loo_TextCompare.ContentsEqual("",1)
if (loo_Credentials.JsonTypeOf("secret_key") <> 1) OR (li_SameText2 = 1) then
    Write-Debug "Missing or invalid secret_key."
    destroy loo_TextCompare
    destroy loo_Credentials
    return
end if

//  General purpose bucket in the commercial AWS partition.
ls_Region = "us-west-2"
ls_BucketName = "amzn-s3-demo-bucket"
loo_Endpoint = create oleobject
li_rc = loo_Endpoint.ConnectToNewObject("Chilkat.StringBuilder")

li_Success = loo_Endpoint.Append(ls_BucketName)
if li_Success <> 1 then
    Write-Debug "Could not build text."
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    return
end if

li_Success = loo_Endpoint.Append(".")
if li_Success <> 1 then
    Write-Debug "Could not build text."
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    return
end if

li_Success = loo_Endpoint.Append("s3.")
if li_Success <> 1 then
    Write-Debug "Could not build text."
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    return
end if

li_Success = loo_Endpoint.Append(ls_Region)
if li_Success <> 1 then
    Write-Debug "Could not build text."
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    return
end if

li_Success = loo_Endpoint.Append(".amazonaws.com")
if li_Success <> 1 then
    Write-Debug "Could not build text."
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    return
end if

loo_Aws = create oleobject
li_rc = loo_Aws.ConnectToNewObject("Chilkat.AuthAws")

loo_Aws.AccessKey = loo_Credentials.StringOf("access_key")
loo_Aws.SecretKey = loo_Credentials.StringOf("secret_key")
loo_Aws.Region = ls_Region
loo_Aws.ServiceName = "s3"
loo_Aws.SignatureVersion = 4
loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat.Rest")

loo_Rest.ConnectTimeoutMs = 20000
loo_Rest.IdleTimeoutMs = 60000
li_Success = loo_Rest.SetAuthAws(loo_Aws)
if li_Success <> 1 then
    Write-Debug "Could not configure AWS signing."
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    return
end if

//  Temporary credentials require this token in every signed query.
//  Keep request URLs private. Do not clear this parameter between requests.
if loo_Credentials.HasMember("session_token") = 1 then
    if loo_Credentials.JsonTypeOf("session_token") <> 1 then
        Write-Debug "session_token must be a string."
        destroy loo_TextCompare
        destroy loo_Credentials
        destroy loo_Endpoint
        destroy loo_Aws
        destroy loo_Rest
        return
    end if

    loo_TextCompare.Clear()
    loo_TextCompare.SetString(loo_Credentials.StringOf("session_token"))
    li_SameText3 = loo_TextCompare.ContentsEqual("",1)
    if li_SameText3 <> 1 then
        li_Success = loo_Rest.AddQueryParam("X-Amz-Security-Token",loo_Credentials.StringOf("session_token"))
        if li_Success <> 1 then
            Write-Debug "Could not prepare the request."
            destroy loo_TextCompare
            destroy loo_Credentials
            destroy loo_Endpoint
            destroy loo_Aws
            destroy loo_Rest
            return
        end if

    end if

end if

//  Connect to the SAME hostname used for TLS verification and request signing.
loo_Connection = create oleobject
li_rc = loo_Connection.ConnectToNewObject("Chilkat.Socket")

loo_Connection.RequireSslCertVerify = 1
loo_Connection.MaxReadIdleMs = 60000
loo_Connection.MaxSendIdleMs = 60000
li_Success = loo_Connection.Connect(loo_Endpoint.GetAsString(),443,1,20000)
if li_Success <> 1 then
    Write-Debug "TLS connection failed; inspect diagnostics privately."
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Connection
    return
end if

li_Success = loo_Rest.UseConnection(loo_Connection,1)
if li_Success <> 1 then
    Write-Debug "Could not attach the TLS connection."
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Connection
    return
end if

loo_Xml = create oleobject
li_rc = loo_Xml.ConnectToNewObject("Chilkat.Xml")

loo_Xml.Strict = 1
loo_State = create oleobject
li_rc = loo_State.ConnectToNewObject("Chilkat.JsonObject")

loo_State.Strict = 1
li_Success = loo_State.LoadFile("s3-multipart.json")
if li_Success <> 1 then
    Write-Debug "Could not load multipart state."
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_Xml
    destroy loo_State
    return
end if

loo_TextCompare.Clear()
loo_TextCompare.SetString(loo_State.StringOf("bucket"))
li_SameText4 = loo_TextCompare.ContentsEqual("",1)
if (loo_State.JsonTypeOf("bucket") <> 1) OR (li_SameText4 = 1) then
    Write-Debug "Invalid multipart state field: bucket"
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_Xml
    destroy loo_State
    return
end if

loo_TextCompare.Clear()
loo_TextCompare.SetString(loo_State.StringOf("region"))
li_SameText5 = loo_TextCompare.ContentsEqual("",1)
if (loo_State.JsonTypeOf("region") <> 1) OR (li_SameText5 = 1) then
    Write-Debug "Invalid multipart state field: region"
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_Xml
    destroy loo_State
    return
end if

loo_TextCompare.Clear()
loo_TextCompare.SetString(loo_State.StringOf("key"))
li_SameText6 = loo_TextCompare.ContentsEqual("",1)
if (loo_State.JsonTypeOf("key") <> 1) OR (li_SameText6 = 1) then
    Write-Debug "Invalid multipart state field: key"
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_Xml
    destroy loo_State
    return
end if

loo_TextCompare.Clear()
loo_TextCompare.SetString(loo_State.StringOf("upload_id"))
li_SameText7 = loo_TextCompare.ContentsEqual("",1)
if (loo_State.JsonTypeOf("upload_id") <> 1) OR (li_SameText7 = 1) then
    Write-Debug "Invalid multipart state field: upload_id"
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_Xml
    destroy loo_State
    return
end if

loo_TextCompare.Clear()
loo_TextCompare.SetString(loo_State.StringOf("bucket"))
li_SameText8 = loo_TextCompare.ContentsEqual(ls_BucketName,1)
loo_TextCompare.Clear()
loo_TextCompare.SetString(loo_State.StringOf("region"))
li_SameText9 = loo_TextCompare.ContentsEqual(ls_Region,1)
if (li_SameText8 <> 1) OR (li_SameText9 <> 1) then
    Write-Debug "Multipart state belongs to another bucket or region."
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_Xml
    destroy loo_State
    return
end if

ls_UploadId = loo_State.StringOf("upload_id")
//  Supply an unencoded object key, not a URL. Preserve slashes in the key.
ls_ObjectKey = loo_State.StringOf("key")
loo_ObjectPath = create oleobject
li_rc = loo_ObjectPath.ConnectToNewObject("Chilkat.StringBuilder")

li_Success = loo_ObjectPath.Append(ls_ObjectKey)
if li_Success <> 1 then
    Write-Debug "Could not build text."
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_Xml
    destroy loo_State
    destroy loo_ObjectPath
    return
end if

li_Success = loo_ObjectPath.Encode("url_rfc3986","utf-8")
if li_Success <> 1 then
    Write-Debug "Could not encode the object key."
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_Xml
    destroy loo_State
    destroy loo_ObjectPath
    return
end if

li_RestoredSlashes = loo_ObjectPath.Replace("%2F","/")
li_Success = loo_ObjectPath.Prepend("/")
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_Xml
    destroy loo_State
    destroy loo_ObjectPath
    return
end if

//  Keep this file unchanged throughout the upload workflow.
ls_InputFile = "qa_data/files/example.bin"
li_PartSize = 8388608
loo_Files = create oleobject
li_rc = loo_Files.ConnectToNewObject("Chilkat.FileAccess")

li_Success = loo_Files.OpenForRead(ls_InputFile)
if li_Success <> 1 then
    Write-Debug "Could not open the input file."
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_Xml
    destroy loo_State
    destroy loo_ObjectPath
    destroy loo_Files
    return
end if

li_NumParts = loo_Files.GetNumBlocks(li_PartSize)
loo_Files.FileClose()
if (li_NumParts < 1) OR (li_NumParts > 10000) then
    Write-Debug "Choose a larger part size for more than 10000 parts; use PutObject for an empty file."
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_Xml
    destroy loo_State
    destroy loo_ObjectPath
    destroy loo_Files
    return
end if

//  Invalidate any prior completion record before changing uploaded parts.
loo_State.Delete("completion_xml")
loo_State.Delete("part_count")
li_Success = loo_State.WriteFile("s3-multipart.json")
if li_Success <> 1 then
    Write-Debug "Could not invalidate the prior completion record."
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_Xml
    destroy loo_State
    destroy loo_ObjectPath
    destroy loo_Files
    return
end if

//  This demonstration uploads EVERY part again if restarted. It never skips a
//  part using an unbound/stale partsList.xml. Re-uploading a part replaces it.
loo_Parts = create oleobject
li_rc = loo_Parts.ConnectToNewObject("Chilkat.Xml")

loo_Parts.Tag = "CompleteMultipartUpload"
li_Success = loo_Parts.AddAttribute("xmlns","http://s3.amazonaws.com/doc/2006-03-01/")
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_Xml
    destroy loo_State
    destroy loo_ObjectPath
    destroy loo_Files
    destroy loo_Parts
    return
end if

li_Success = loo_Rest.AddQueryParam("uploadId",ls_UploadId)
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_Xml
    destroy loo_State
    destroy loo_ObjectPath
    destroy loo_Files
    destroy loo_Parts
    return
end if

loo_PartNumberText = create oleobject
li_rc = loo_PartNumberText.ConnectToNewObject("Chilkat.StringBuilder")

li_PartNumber = 1
do while (li_PartNumber <= li_NumParts)
    loo_PartNumberText.Clear()
    li_Success = loo_PartNumberText.AppendInt(li_PartNumber)
    if li_Success <> 1 then
        Write-Debug "Could not prepare the request."
        destroy loo_TextCompare
        destroy loo_Credentials
        destroy loo_Endpoint
        destroy loo_Aws
        destroy loo_Rest
        destroy loo_Connection
        destroy loo_Xml
        destroy loo_State
        destroy loo_ObjectPath
        destroy loo_Files
        destroy loo_Parts
        destroy loo_PartNumberText
        return
    end if

    if li_PartNumber > 1 then
        li_Success = loo_Rest.RemoveQueryParam("partNumber")
        if li_Success <> 1 then
            Write-Debug "Could not prepare the request."
            destroy loo_TextCompare
            destroy loo_Credentials
            destroy loo_Endpoint
            destroy loo_Aws
            destroy loo_Rest
            destroy loo_Connection
            destroy loo_Xml
            destroy loo_State
            destroy loo_ObjectPath
            destroy loo_Files
            destroy loo_Parts
            destroy loo_PartNumberText
            return
        end if

    end if

    li_Success = loo_Rest.AddQueryParam("partNumber",loo_PartNumberText.GetAsString())
    if li_Success <> 1 then
        Write-Debug "Could not prepare the request."
        destroy loo_TextCompare
        destroy loo_Credentials
        destroy loo_Endpoint
        destroy loo_Aws
        destroy loo_Rest
        destroy loo_Connection
        destroy loo_Xml
        destroy loo_State
        destroy loo_ObjectPath
        destroy loo_Files
        destroy loo_Parts
        destroy loo_PartNumberText
        return
    end if

    //  Buffer only this 8 MiB part. Rest authenticates UploadPart with SigV4;
    //  this library uses S3's supported UNSIGNED-PAYLOAD mode for this operation.
    //  HTTPS protects the transfer; an explicit checksum is a separate option.
    loo_Part = create oleobject
    li_rc = loo_Part.ConnectToNewObject("Chilkat.BinData")

    li_Success = loo_Files.OpenForRead(ls_InputFile)
    if li_Success <> 1 then
        Write-Debug "Could not reopen the unchanged input file."
        destroy loo_TextCompare
        destroy loo_Credentials
        destroy loo_Endpoint
        destroy loo_Aws
        destroy loo_Rest
        destroy loo_Connection
        destroy loo_Xml
        destroy loo_State
        destroy loo_ObjectPath
        destroy loo_Files
        destroy loo_Parts
        destroy loo_PartNumberText
        destroy loo_Part
        return
    end if

    li_Success = loo_Files.ReadBlockBd(li_PartNumber - 1,li_PartSize,loo_Part)
    loo_Files.FileClose()
    if (li_Success <> 1) OR (loo_Part.NumBytes = 0) then
        Write-Debug "Could not read the expected part."
        destroy loo_TextCompare
        destroy loo_Credentials
        destroy loo_Endpoint
        destroy loo_Aws
        destroy loo_Rest
        destroy loo_Connection
        destroy loo_Xml
        destroy loo_State
        destroy loo_ObjectPath
        destroy loo_Files
        destroy loo_Parts
        destroy loo_PartNumberText
        destroy loo_Part
        return
    end if

    loo_PartResponse = create oleobject
    li_rc = loo_PartResponse.ConnectToNewObject("Chilkat.StringBuilder")

    li_Success = loo_Rest.FullRequestBd("PUT",loo_ObjectPath.GetAsString(),loo_Part,loo_PartResponse)
    if li_Success <> 1 then
        Write-Debug "Part upload did not complete; inspect diagnostics privately."
        destroy loo_TextCompare
        destroy loo_Credentials
        destroy loo_Endpoint
        destroy loo_Aws
        destroy loo_Rest
        destroy loo_Connection
        destroy loo_Xml
        destroy loo_State
        destroy loo_ObjectPath
        destroy loo_Files
        destroy loo_Parts
        destroy loo_PartNumberText
        destroy loo_Part
        destroy loo_PartResponse
        return
    end if

    ls_ResponseBody = loo_PartResponse.GetAsString()
    if loo_Rest.ResponseStatusCode <> 200 then
        Write-Debug "S3 HTTP status: " + string(loo_Rest.ResponseStatusCode)
        li_Success = loo_Xml.LoadXml(ls_ResponseBody)
        loo_TextCompare.Clear()
        loo_TextCompare.SetString(loo_Xml.Tag)
        li_SameText10 = loo_TextCompare.ContentsEqual("Error",1)
        if (li_Success = 1) AND (li_SameText10 = 1) then
            Write-Debug "S3 error code: " + loo_Xml.GetChildContent("Code")
        end if

        //  Keep signed headers, credentials, URLs, and full diagnostics private.
        //  A timeout may leave a write's outcome uncertain. Check before retrying.
        destroy loo_TextCompare
        destroy loo_Credentials
        destroy loo_Endpoint
        destroy loo_Aws
        destroy loo_Rest
        destroy loo_Connection
        destroy loo_Xml
        destroy loo_State
        destroy loo_ObjectPath
        destroy loo_Files
        destroy loo_Parts
        destroy loo_PartNumberText
        destroy loo_Part
        destroy loo_PartResponse
        return
    end if

    ls_Etag = loo_Rest.ResponseHdrByName("ETag")
    loo_TextCompare.Clear()
    loo_TextCompare.SetString(ls_Etag)
    li_SameText11 = loo_TextCompare.ContentsEqual("",1)
    if (loo_Rest.LastMethodSuccess <> 1) OR (li_SameText11 = 1) then
        Write-Debug "Missing part ETag."
        destroy loo_TextCompare
        destroy loo_Credentials
        destroy loo_Endpoint
        destroy loo_Aws
        destroy loo_Rest
        destroy loo_Connection
        destroy loo_Xml
        destroy loo_State
        destroy loo_ObjectPath
        destroy loo_Files
        destroy loo_Parts
        destroy loo_PartNumberText
        destroy loo_Part
        destroy loo_PartResponse
        return
    end if

    loo_Parts.I = li_PartNumber - 1
    loo_Parts.UpdateChildContentInt("Part[i]|PartNumber",li_PartNumber)
    loo_Parts.UpdateChildContent("Part[i]|ETag",ls_Etag)
    Write-Debug "Uploaded part: " + string(li_PartNumber)
    li_PartNumber = li_PartNumber + 1
loop
//  Save only after every part succeeded. Bind the completion body to this state.
li_Success = loo_State.UpdateString("completion_xml",loo_Parts.GetXml())
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_Xml
    destroy loo_State
    destroy loo_ObjectPath
    destroy loo_Files
    destroy loo_Parts
    destroy loo_PartNumberText
    destroy loo_Part
    destroy loo_PartResponse
    return
end if

li_Success = loo_State.UpdateInt("part_count",li_NumParts)
if li_Success <> 1 then
    Write-Debug "Could not prepare the request."
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_Xml
    destroy loo_State
    destroy loo_ObjectPath
    destroy loo_Files
    destroy loo_Parts
    destroy loo_PartNumberText
    destroy loo_Part
    destroy loo_PartResponse
    return
end if

li_Success = loo_State.WriteFile("s3-multipart.json")
if li_Success <> 1 then
    Write-Debug "Parts uploaded but state save failed; do not complete with stale state."
    destroy loo_TextCompare
    destroy loo_Credentials
    destroy loo_Endpoint
    destroy loo_Aws
    destroy loo_Rest
    destroy loo_Connection
    destroy loo_Xml
    destroy loo_State
    destroy loo_ObjectPath
    destroy loo_Files
    destroy loo_Parts
    destroy loo_PartNumberText
    destroy loo_Part
    destroy loo_PartResponse
    return
end if

Write-Debug "All parts uploaded and completion data saved."


destroy loo_TextCompare
destroy loo_Credentials
destroy loo_Endpoint
destroy loo_Aws
destroy loo_Rest
destroy loo_Connection
destroy loo_Xml
destroy loo_State
destroy loo_ObjectPath
destroy loo_Files
destroy loo_Parts
destroy loo_PartNumberText
destroy loo_Part
destroy loo_PartResponse