Amazon Glacier: List Uploaded Parts with Pagination
See more Amazon Glacier Examples
For existing Amazon Glacier vault customers. The standalone vault service is closed to new customers. These examples use its REST API version 2012-06-01, not the S3 bucket APIs used by S3 Glacier storage classes. See AWS service guidance.
Lists all part ranges and their tree hashes for one in-progress upload. Range endpoints are inclusive and remain strings so large offsets are not truncated. Uses the documented page limit of 50, follows Marker, and detects incomplete or repeated pagination. The resume example additionally compares these server hashes with local bytes.
Uses AWS Signature Version 4 with service glacier. Set the region once; the example builds the commercial AWS endpoint. Other partitions require the appropriate endpoint suffix. /-/ selects the signing account; change the vault name and IDs to your own resources. Load private qa_data/aws/glacier.json with string fields access_key, secret_key, and session_token for temporary credentials. Prefer short-lived role credentials. This sample does not discover profiles or refresh credentials. TLS certificate verification is enabled explicitly.
Checks transport completion, the operation-specific HTTP status, and parsed data separately. Inspect full diagnostics privately. Renew expired credentials; use bounded backoff with jitter for retryable reads. Uploads and job initiation can succeed before a connection fails, so do not blindly resubmit them. Configure IAM permissions for only the required operations and vault resources.
Chilkat B4X Downloads
' Assumes Chilkat is unlocked. See Global Unlock Sample.
Dim success As Boolean = False
' Private configuration, not a file in public web content or source control.
' Load current IAM credentials authorized for the Glacier operation.
Dim credentials As ChilkatJsonObject
credentials.Initialize
credentials.Strict = True
success = credentials.LoadFile("qa_data/aws/glacier.json")
If success <> True Then
Log("Could not load private AWS credentials.")
Return
End If
If (credentials.JsonTypeOf("access_key") <> 1) Or (credentials.StringOf("access_key") = "") Then
Log("Missing or invalid access_key.")
Return
End If
If (credentials.JsonTypeOf("secret_key") <> 1) Or (credentials.StringOf("secret_key") = "") Then
Log("Missing or invalid secret_key.")
Return
End If
' Set this once to the region containing the vault.
Dim region As String = "us-west-2"
Dim endpoint As ChilkatStringBuilder
endpoint.Initialize
endpoint.Append("glacier.")
endpoint.Append(region)
endpoint.Append(".amazonaws.com")
Dim aws As ChilkatAuthAws
aws.Initialize
aws.AccessKey = credentials.StringOf("access_key")
aws.SecretKey = credentials.StringOf("secret_key")
aws.Region = region
aws.ServiceName = "glacier"
aws.SignatureVersion = 4
Dim rest As ChilkatRest
rest.Initialize("rest")
rest.ConnectTimeoutMs = 20000
rest.IdleTimeoutMs = 60000
success = rest.SetAuthAws(aws)
If success <> True Then
Log("Could not configure AWS signing.")
Return
End If
' Temporary IAM/STS credentials require their session token on every signed request.
' Include the token in the signed query. Keep request URLs and diagnostics private.
' Leave session_token absent or empty only for credentials that do not have one.
If credentials.HasMember("session_token") = True Then
If credentials.JsonTypeOf("session_token") <> 1 Then
Log("session_token must be a string.")
Return
End If
If credentials.StringOf("session_token") <> "" Then
success = rest.AddQueryParam("X-Amz-Security-Token", credentials.StringOf("session_token"))
If success <> True Then
Log("Could not set the session-token parameter.")
Return
End If
End If
End If
' Supply a Socket to explicitly enable TLS certificate verification.
Dim connection As ChilkatSocket
connection.Initialize("connection")
connection.RequireSslCertVerify = True
connection.MaxReadIdleMs = 60000
connection.MaxSendIdleMs = 60000
success = connection.Connect(endpoint.GetAsString, 443, True, 20000)
If success <> True Then
Log("TLS connection failed; inspect diagnostics privately.")
Return
End If
success = rest.UseConnection(connection, True)
If success <> True Then
Log("Could not attach the TLS connection.")
Return
End If
success = rest.AddHeader("x-amz-glacier-version", "2012-06-01")
If success <> True Then
Log("Could not set x-amz-glacier-version.")
Return
End If
' A hyphen selects the account belonging to the signing credentials.
' Use the original, URL-safe vault name and IDs returned by Glacier.
success = rest.AddPathParam("{vault}", "chilkat")
If success <> True Then
Log("Could not set vault name.")
Return
End If
Dim body As ChilkatJsonObject
body.Initialize
Dim result As ChilkatJsonObject
result.Initialize
result.Strict = True
Dim error As ChilkatJsonObject
error.Initialize
error.Strict = True
Dim requestBody As ChilkatStringBuilder
requestBody.Initialize
Dim responseBody As ChilkatStringBuilder
responseBody.Initialize
Dim uploadId As String = "UPLOAD_ID"
success = rest.AddPathParam("{upload}", uploadId)
If success <> True Then
Log("Could not set upload ID.")
Return
End If
success = rest.AddQueryParam("limit", "50")
If success <> True Then
Log("Could not set page limit.")
Return
End If
Dim seenMarkers As ChilkatHashtable
seenMarkers.Initialize
Dim marker As String = ""
Dim more As Boolean = True
Dim page As Int = 0
Do While (more = True)
If page = 1000 Then
Log("Page limit reached; listing is incomplete.")
Return
End If
page = page + 1
If marker <> "" Then
success = rest.AddQueryParam("marker", marker)
If success <> True Then
Log("Could not set marker.")
Return
End If
End If
success = rest.FullRequestNoBodySb("GET", "/-/vaults/{vault}/multipart-uploads/{upload}", responseBody)
If success <> True Then
Log("Request did not complete; inspect diagnostics privately. Check state before retrying a change.")
Return
End If
If rest.ResponseStatusCode <> 200 Then
Log("Glacier HTTP status: " & rest.ResponseStatusCode)
success = error.LoadSb(responseBody)
If success = True Then
If error.JsonTypeOf("code") = 1 Then
Log("AWS error code: " & error.StringOf("code"))
End If
End If
Log("AWS request ID: " & rest.ResponseHdrByName("x-amzn-RequestId"))
' Inspect full errors privately. An HTTP error is not a successful operation.
Return
End If
success = result.LoadSb(responseBody)
If success <> True Then
Log("Expected valid JSON response.")
Return
End If
If result.JsonTypeOf("MultipartUploadId") <> 1 Then
Log("Missing or invalid MultipartUploadId.")
Return
End If
If result.StringOf("MultipartUploadId") = "" Then
Log("Empty MultipartUploadId.")
Return
End If
If result.JsonTypeOf("PartSizeInBytes") <> 2 Then
Log("Missing or invalid PartSizeInBytes.")
Return
End If
If result.StringOf("MultipartUploadId") <> uploadId Then
Log("Unexpected upload ID.")
Return
End If
Log("Part size: " & result.StringOf("PartSizeInBytes"))
If result.JsonTypeOf("Parts") <> 4 Then
Log("Missing or invalid Parts.")
Return
End If
Dim i As Int = 0
Do While (i < result.SizeOfArray("Parts"))
result.I = i
If result.JsonTypeOf("Parts[i].RangeInBytes") <> 1 Then
Log("Missing or invalid Parts[i].RangeInBytes.")
Return
End If
If result.StringOf("Parts[i].RangeInBytes") = "" Then
Log("Empty Parts[i].RangeInBytes.")
Return
End If
If result.JsonTypeOf("Parts[i].SHA256TreeHash") <> 1 Then
Log("Missing or invalid Parts[i].SHA256TreeHash.")
Return
End If
If result.StringOf("Parts[i].SHA256TreeHash") = "" Then
Log("Empty Parts[i].SHA256TreeHash.")
Return
End If
Log("Range: " & result.StringOf("Parts[i].RangeInBytes"))
Log("Tree hash: " & result.StringOf("Parts[i].SHA256TreeHash"))
i = i + 1
Loop
more = False
If result.JsonTypeOf("Marker") = 1 Then
marker = result.StringOf("Marker")
If marker = "" Then
Log("Empty marker; listing is incomplete.")
Return
End If
If seenMarkers.Contains(marker) = True Then
Log("Repeated marker; listing is incomplete.")
Return
End If
success = seenMarkers.AddStr(marker, "seen")
If success <> True Then
Log("Could not track pagination.")
Return
End If
more = True
Else
If result.JsonTypeOf("Marker") <> 6 Then
Log("Missing or invalid Marker; listing is incomplete.")
Return
End If
End If
Loop
success = rest.RemoveQueryParam("limit")
If success <> True Then
Log("Could not clear limit.")
Return
End If
If marker <> "" Then
success = rest.RemoveQueryParam("marker")
If success <> True Then
Log("Could not clear marker.")
Return
End If
End If
Log("Multipart part listing complete.")