Amazon S3 (Chilkat.Http) API Guide

Use Chilkat.Http to manage S3 buckets, list objects, transfer files, share presigned URLs, and work with object versions. This guide connects 41 complete examples, from a simple upload to checkpointed multipart uploads and checksum-verified resumable downloads.

Before making requests

The examples require Chilkat 11.6.0 or later and an unlocked library. They target S3 general purpose buckets in the commercial AWS partition. Directory buckets/S3 Express, access-point ARNs, Outposts, and other specialized endpoints need their own addressing and authentication handling. Select the actual bucket region, rather than the application's location.

Read credentials from a private qa_data/aws/s3.json file containing nonempty string fields access_key and secret_key, plus session_token when using temporary credentials. Prefer short-lived role credentials and the permissions needed for the chosen operations. These examples read that named file; they do not discover AWS profiles, obtain role credentials, or refresh expired credentials. Keep the file outside public web content and source control. Replace the sample bucket, key, version/upload IDs, and local paths before running.

How these examples use Chilkat.Http

Choose the request style that exposes the controls you need
Request styleUse and configuration
S3 convenience methodsMethods such as S3_UploadFile, S3_DownloadFile, and S3_ListBucketObjects handle signing. Configure AwsAccessKey, AwsSecretKey, optional AwsSessionToken, AwsRegion, and AwsEndpoint. The examples use Signature Version 4.
Explicit signed Http requestsThe advanced examples construct the exact URL, query, headers, and payload hash, then use Crypt2 for SigV4 signing. They send with HttpNoBody, HttpStr, HttpFile, HttpBd, or Download. This gives access to pagination parameters, conditional/checksum headers, and the full response.
Presigned requestsS3_GenPresignedUrl and S3_GenPresignedUrlPUT create signed URLs locally. The upload example uses a separate Http instance without AWS credentials to consume the URL.

Setting the Aws* properties for convenience methods does not replace the signing block in the explicit-request examples. Their signing scope uses the bucket region and service s3; the canonical path, sorted encoded query, signed headers, and payload must match what is sent. Keep the clock accurate and do not change a signed request afterward. Those blocks implement the requests shown, not a general-purpose URL signing library. See the Http reference and S3 SigV4 signing rules.

For the regional examples, AwsEndpoint is a hostname such as s3.us-west-2.amazonaws.com, without https://. Explicit object requests use bucket-name.s3.us-west-2.amazonaws.com. TLS certificate verification is enabled and redirects are not silently followed; correct a mismatched region instead. Keep detailed HTTP diagnostics and signed URLs private.

An object key is a case-sensitive name, not a local filesystem path. A slash can act as a prefix separator, and a leading slash is part of the key. The examples encode the original key once while preserving separator slashes; this also preserves a literal %2F in a key. Do not apply the encoding step twice. Opaque continuation tokens, version IDs, and upload IDs are encoded as query values, not normalized as paths. The explicit object examples exclude leading slashes and dot path segments to keep their URL handling unambiguous.

Buckets

Use Paginated Bucket Listing with Filters for a complete account listing. It sends max-buckets=1000, retains optional prefix and bucket-region filters, and follows ContinuationToken. A bucket-region filter must match the request endpoint's region. AWS recommends paginated ListBuckets; unpaginated requests are rejected for accounts with a general purpose bucket quota above 10,000. The convenience-method example remains useful for its simpler interface but does not paginate. See ListBuckets.

The simple bucket creation example targets us-east-1. For another region, use the regional example: it signs a PUT URL and sends CreateBucketConfiguration XML with the matching LocationConstraint through Http. In us-east-1 the body is empty. Choose an unused bucket name, and reconcile an uncertain creation response before retrying. Deletion requires an empty bucket; in a versioned bucket, old versions and delete markers also count. See CreateBucket and DeleteBucket.

Listing Objects

The object-listing examples use ListObjectsV2, requesting up to 1,000 results per page. Continue while IsTruncated is true and pass the returned NextContinuationToken into the next request. An empty page is not necessarily the last page. The examples validate XML and required fields, reject repeated or missing continuation tokens, and report incomplete enumeration if their 10,000-page bound is reached. See ListObjectsV2.

A prefix such as images/ restricts the names returned. Adding delimiter / groups deeper names into CommonPrefixes; those groups are not downloadable folder objects. The examples request encoding-type=url and decode returned keys/prefixes once. Sizes remain decimal strings to avoid 32-bit overflow. The XML example processes every page rather than treating the first response as the whole bucket. Pagination is not an atomic snapshot of a changing bucket.

Uploads

Start with Upload a File for binary data or Upload UTF-8 Text for text. Supply the intended content type and keep the source file unchanged during the request. A PUT to an existing key replaces its current contents or creates another version when versioning is enabled. Use the conditional example below when the write must succeed only if the key is absent. Single-PUT examples do not automatically switch to multipart for larger files; see S3 upload options and limits.

User-defined metadata is sent as x-amz-meta-* headers during upload and read later with HEAD. It is separate from the object's bytes and from object tags. The transfer-acceleration example uses a presigned upload against s3-accelerate.amazonaws.com, while retaining the bucket region for signing. Acceleration must already be enabled; it needs a supported bucket and a DNS-compatible name without periods, and additional charges can apply. See Transfer Acceleration.

The public-read ACL example is for legacy ACL-enabled buckets. It requires an explicit opt-in in the sample. New buckets default to Bucket owner enforced ownership with ACLs disabled; Block Public Access can also reject public access. Keep those settings unless the application deliberately requires a different access model. Use policy-based access or a presigned URL as appropriate. See S3 Object Ownership.

Multipart Uploads and Recovery

The multipart examples implement initiate, upload parts, and complete through explicitly signed Http requests. They save an upload ID and source identity in a private checkpoint before sending parts. Each part has a SHA-256 checksum; completion includes the ordered part numbers, returned ETags, and checksums. The sample uses a COMPOSITE SHA-256 checksum and verifies the returned combined value. ETags are completion identifiers, not assumed MD5 hashes.

Run Resume and Recover a Multipart Upload after an interruption. It checks the original destination and source hash, lists all remote parts, and reuses only parts with matching checksum and size. Missing or mismatched parts are uploaded again. If completion was attempted but its response was lost, a later NoSuchUpload triggers reconciliation: checksum-enabled HEAD must match the upload's random identity token, source hash, size, and composite checksum. A missing upload alone is never treated as completion. If another write has replaced the object, inspect version history before deciding what happened.

Read the completion body even after HTTP 200. S3 can begin a completion response successfully and then return an embedded error. The examples require the expected XML result and checksum before saving a completion receipt. See CompleteMultipartUpload.

Use the two listing examples to inspect an upload's parts or enumerate incomplete uploads. Part listing follows a part-number marker; upload listing follows the key/upload-ID marker pair. Stop upload workers before aborting. The abort example sends DELETE, checks ListParts for NoSuchUpload, and makes at most three attempts if an upload remains. It does not delete a completed object. Incomplete parts incur charges until completion or cleanup; a lifecycle rule can address abandoned uploads. See AbortMultipartUpload and multipart upload management.

These demonstrations use fixed 8 MiB parts and at most 10,000 parts: a sample limit of 78.125 GiB, not the S3 service limit. Use one process per checkpoint and keep the upload source immutable. Retain the checkpoint after failure; restarting initiation with an existing checkpoint is not a resume. An uncertain initiation can leave an upload without a saved ID, so inspect incomplete uploads before starting another.

Downloads and Ranges

The file examples write a temporary file, check the expected HTTP status and actual byte count, then rename it to an unused final path. The text examples decode UTF-8 into memory and support an empty result. The version example requests a specific opaque version ID. The CloudTrail example downloads a gzip-compressed log, decompresses it, validates JSON and its Records array, and saves the result.

Download an Object Byte Range reads HEAD metadata, then requests the first 1 MiB using Range: bytes=0-1048575 and If-Match, with a returned version ID when available. Range endpoints are inclusive. The sample requires HTTP 206, the exact Content-Range, length, and ETag, and the actual number of bytes written. A whole-object checksum cannot verify just that range. An archived S3 object must be restored before retrieval; this is not a standalone Glacier retrieval job. See GetObject.

Resume a Version-Pinned, Checksum-Verified Download saves the selected version, ETag, size, and stored SHA-256 checksum with its destination settings. Later runs reuse that selected version rather than switching to a newer current version. Each cached chunk is rehashed before reuse; partial chunks are downloaded again. A server that ignores Range and sends HTTP 200 does not produce a committed chunk. The assembled file must pass a full-object SHA-256 and size check before becoming the final file.

The resumable example requires a stored FULL_OBJECT SHA-256 checksum and nonempty input; use the single verified-download example for empty objects. It uses 8 MiB chunks with a 10,000-chunk demonstration bound and portable large offsets. Start with a private empty cache, run one process, keep cache and final output on the same filesystem, and allow roughly twice the object size plus a temporary chunk in disk space. Corrupt cache or changed object identity stops the operation; retain valid progress for investigation.

Checksums and SSE-KMS

Integrity and identity values have different purposes
ValueHow the examples use it
ETagAn opaque validator for conditional requests and a part identifier for multipart completion. Do not treat every ETag as an MD5 digest.
FULL_OBJECT SHA-256A base64 digest of the entire object's bytes. The checksum upload, verified download, and resumable download examples use this form.
COMPOSITE SHA-256Combines the ordered binary part digests and includes a part-count suffix. The multipart examples calculate and verify this form; hashing the complete local file once does not produce the same value.
Version IDSelects an object version. Preserve it as an opaque string, including the literal null when that is the actual version ID. It is not a content checksum.

The checksum upload streams a file with HttpFile, signs its hexadecimal SHA-256 payload hash, sends the base64 x-amz-checksum-sha256 value, and checks the returned checksum. Keep the file unchanged between hashing and sending. The SSE-KMS variant also signs the encryption mode, KMS key ARN, and S3 Bucket Key request, then checks the returned encryption/key ARN. Configure a key in the bucket region with suitable key-policy and IAM access. The operation changes the requested encryption of this object, not the bucket's defaults.

The metadata example sends HEAD with x-amz-checksum-mode=ENABLED and displays available checksums and their type. An absent checksum is not an empty hash. The verified download requires FULL_OBJECT SHA-256, pins the version/ETag, checks response metadata, and hashes the downloaded bytes before renaming. KMS-encrypted objects require applicable KMS permissions; retrieving checksum metadata can also need kms:GenerateDataKey and kms:Decrypt. Do not send upload encryption headers on these HEAD/GET requests. See HeadObject and multipart checksum verification.

Metadata and Deleting Objects

HEAD returns headers without the object body. The user-metadata example selects x-amz-meta-* fields; the checksum HEAD example above also reads integrity/encryption metadata. A 403 does not prove that an object is absent. HEAD errors may have no XML body, so use the HTTP status and request identifiers when investigating.

A delete without a version ID removes an unversioned object; in a versioning-enabled bucket it normally creates a delete marker instead of erasing older versions. Deleting a specific version is permanent, and removing a current delete marker can expose an older version. Object Lock, legal holds, MFA Delete, and access policies can prevent a request. The examples do not bypass those controls. See DeleteObject.

The batch example sends explicit DeleteObjects XML through Http and inspects every Error element in the original response. A batch accepts up to 1,000 identifiers, and HTTP 200 can contain individual failures. Quiet mode can omit successful entries; a missing key can count as successful deletion. Retry only failed identifiers when appropriate rather than blindly repeating an entire versioned delete batch. See DeleteObjects.

Versions and Conditional Operations

The version-listing example displays both Version and DeleteMarker entries, applies a prefix filter, and paginates with the pair NextKeyMarker/NextVersionIdMarker. Keys are URL-decoded once; version IDs remain opaque. The permanent-delete example requires an explicit version ID. It does not enable versioning or turn an ordinary delete into a version purge. See ListObjectVersions.

Create an Object Only If Absent signs If-None-Match: * and a SHA-256 checksum. HTTP 412 means the create-only write was not applied because an object exists; 409 signals a conflicting concurrent operation and requires reconciliation before retrying. In a versioned bucket the condition concerns the current object, so a current delete marker can permit a new write. See PutObject.

Download Only If the ETag Still Matches sends the exact quoted ETag using If-Match. It handles 412 without promoting output, then verifies the returned ETag and byte count on success. This tests a validator; it is not checksum verification. Select a version ID when the application must retain the original object version across overwrites.

Presigned URLs and S3-Compatible Providers

A presigned URL grants the holder access to the specified method and object within the signer's permissions. The examples use short expirations and protect the URL from shared logs. Generation is local and does not verify that the bucket, object, credentials, or permissions are valid. A URL can be reused until it expires or becomes invalid; temporary credentials may expire sooner, and policies can further restrict access. See presigned URL behavior.

The basic presigned-upload example signs the host and demonstrates sending bytes with a separate Http instance. It does not bind a particular payload checksum or content type. Uploading can replace an existing key or create another version. Do not append query parameters or change the signed method, path, or host after generating the URL; requests with additional constraints need matching signing logic.

The compatible-provider example reads a separate qa_data/aws/s3-compatible.json file. Use that provider's credentials, endpoint hostname, and signing region; do not send AWS credentials to an unrelated service. S3 compatibility does not imply identical pagination, addressing, versioning, checksum, or error behavior. The example demonstrates the unpaginated bucket helper and validates the returned XML; confirm provider-specific capabilities before adapting other examples.

Troubleshooting and Permissions

Common starting points when a request fails
ObservationWhat to check
Signing error or region redirectBucket region, endpoint, clock, session token, exact key/query encoding, signed headers, and whether the payload changed after hashing.
403 / AccessDeniedIAM and bucket policy, KMS key permissions when applicable, and any access restrictions. Do not treat 403 as proof of a missing object.
412 or 409A failed condition or concurrent operation. Recheck object state; do not silently fall back to an unconditional write or download.
416 or unexpected HTTP 200 for a rangeSelected version, object size, inclusive offsets, and whether the endpoint honored Range. Keep incomplete output separate from the final file.
Timeout, throttling, or 5xxUse bounded backoff where appropriate. A write may have reached S3; reconcile checkpoints and remote state before retrying initiation, completion, or deletion.
HTTP 200 with an error bodyValidate XML and operation-specific results. Multipart completion and batch deletion need body-level error checks.

Typical permissions include s3:ListAllMyBuckets for account bucket listing, s3:ListBucket for object listing, s3:ListBucketVersions for versions, s3:GetObject/s3:GetObjectVersion for reads, and s3:PutObject for writes. Multipart inspection and cleanup use s3:ListBucketMultipartUploads, s3:ListMultipartUploadParts, and s3:AbortMultipartUpload. Deletion uses s3:DeleteObject or s3:DeleteObjectVersion; bucket creation/deletion use their corresponding bucket actions. IAM action names are not always the HTTP operation names. See S3 actions and required permissions.

Check transport completion and the expected HTTP status separately. Explicit response methods provide HttpResponse; streamed downloads expose LastStatus and response headers on Http. For XML errors, retain the error code and request identifiers in appropriate private diagnostics. Do not report success merely because bytes arrived or because the request returned a 2xx status. The linked examples include the operation-specific validation and recovery limits described above.