S3: Create and Use a Presigned Upload URL
See more S3 - HTTP Examples
Uses Chilkat.Http with Amazon S3 general purpose buckets and Signature Version 4. These examples do not cover directory buckets/S3 Express, access-point ARNs, Outposts, or other specialized endpoints. They target the commercial AWS partition; other partitions need their documented endpoint suffix.
Load private qa_data/aws/s3.json containing nonempty string fields access_key and secret_key, plus session_token for temporary credentials. Prefer short-lived role credentials. These samples do not discover AWS profiles or refresh credentials. Set the bucket's actual region and replace sample bucket names and object keys. TLS certificate verification is explicitly enabled. Keep detailed HTTP diagnostics private because they can contain credentials or presigned URLs.
Generates a SigV4 URL valid for 15 minutes, using HTTPS and the bucket's actual signing region. A presigned URL is a bearer credential: protect it from shared logs and untrusted recipients. It remains usable multiple times until expiration or revocation; it is not a one-time URL. Temporary credentials may expire sooner, and bucket policies can further restrict use. SigV4 expiration cannot exceed seven days. Generation is local and does not verify the bucket, object, permissions, or credentials with S3.
The signer needs s3:PutObject. Uploading replaces an existing key or creates a new version. A separate Http instance demonstrates use without AWS credentials. This basic URL signs the host and does not bind Content-Type or a particular payload checksum; add a dedicated constrained-presigning example when those restrictions are needed.
Chilkat PowerShell Downloads
Add-Type -Path "C:\chilkat\ChilkatDotNet47-x64\ChilkatDotNet47.dll"
$success = $false
$stringCompare = New-Object Chilkat.StringBuilder
# This example requires the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
# Load private credentials; never put access keys or session tokens in source.
$credentials = New-Object Chilkat.JsonObject
$credentials.Strict = $true
$success = $credentials.LoadFile("qa_data/aws/s3.json")
if ($success -ne $true) {
$("Could not load private S3 credentials.")
exit
}
$stringCompare.SetString($credentials.StringOf("access_key"))
$stringMatch1 = $stringCompare.ContentsEqual("",$true)
if (($credentials.JsonTypeOf("access_key") -ne 1) -or ($stringMatch1 -eq $true)) {
$("Missing or invalid access_key.")
exit
}
$stringCompare.SetString($credentials.StringOf("secret_key"))
$stringMatch2 = $stringCompare.ContentsEqual("",$true)
if (($credentials.JsonTypeOf("secret_key") -ne 1) -or ($stringMatch2 -eq $true)) {
$("Missing or invalid secret_key.")
exit
}
$http = New-Object Chilkat.Http
$http.AwsAccessKey = $credentials.StringOf("access_key")
$http.AwsSecretKey = $credentials.StringOf("secret_key")
if ($credentials.HasMember("session_token") -eq $true) {
$stringCompare.SetString($credentials.StringOf("session_token"))
$stringMatch3 = $stringCompare.ContentsEqual("",$true)
if (($credentials.JsonTypeOf("session_token") -ne 1) -or ($stringMatch3 -eq $true)) {
$("session_token must be a nonempty string when supplied.")
exit
}
$http.AwsSessionToken = $credentials.StringOf("session_token")
}
# Current Chilkat uses SigV4 by default. Do not select deprecated SigV2.
# Set the actual bucket region, not the caller's location.
$region = "us-west-2"
$http.AwsRegion = $region
$endpoint = New-Object Chilkat.StringBuilder
$endpoint.Append("s3.")
$endpoint.Append($region)
$endpoint.Append(".amazonaws.com")
$http.AwsEndpoint = $endpoint.GetAsString()
$http.RequireSslCertVerify = $true
$http.FollowRedirects = $false
# A region redirect is not success. Correct the endpoint and signing region.
$bucketName = "your-bucket-name"
# A leading slash is part of a key. Do not add one to imitate a file path.
$objectName = "images/seahorse.jpg"
# Start with the original key. Encode once and retain '/' path separators.
# This also protects a literal "%2F" from being interpreted as a slash.
$keyPath = New-Object Chilkat.StringBuilder
$keyPath.Append($http.UrlEncode($objectName))
$slashCount = $keyPath.ReplaceNoCase("%2f","/")
$encodedKey = $keyPath.GetAsString()
$signedUrl = $http.S3_GenPresignedUrl("PUT",$true,$bucketName,$encodedKey,900,"s3")
if ($http.LastMethodSuccess -ne $true) {
$("Could not generate presigned upload URL.")
exit
}
# A PUT URL is used by an HTTP upload client, not browser address-bar navigation.
# The recipient needs this URL, not the signer's AWS credentials.
$uploader = New-Object Chilkat.Http
$uploader.RequireSslCertVerify = $true
$uploader.FollowRedirects = $false
$response = New-Object Chilkat.HttpResponse
$success = $uploader.HttpFile("PUT",$signedUrl,"qa_data/jpg/seahorse.jpg","image/jpeg",$response)
if ($success -ne $true) {
$("Upload transport failed. Inspect diagnostics privately.")
exit
}
if ($response.StatusCode -ne 200) {
$("Unexpected HTTP status: " + $response.StatusCode)
exit
}
$("Presigned upload succeeded.")