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

S3: Upload with a Public-Read ACL (Legacy Buckets)

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.

Uploads a JPEG with the public-read canned ACL. This can grant anonymous read access and is unsuitable for private data.

Legacy ACL-enabled buckets only. New buckets disable ACLs by default, so public-read fails with AccessControlListNotSupported under Bucket owner enforced ownership. Applicable Block Public Access settings can reject or ignore public ACLs. This example does not change ownership or public-access settings. Prefer private objects and presigned downloads or an intentionally configured delivery policy.

Set the explicit opt-in flag only for a bucket already configured to permit this public ACL. Requires s3:PutObject and s3:PutObjectAcl. Successful upload alone does not prove anonymous access is effective.

AWS reference

Chilkat VB.NET Downloads

VB.NET
Dim success As Boolean = False

Dim stringCompare As New Chilkat.StringBuilder
'  Explicit opt-in for this legacy public ACL demonstration.
Dim allowPublicRead As Boolean = False
If (allowPublicRead <> True) Then
    Debug.WriteLine("Public ACL example is disabled. Read its prerequisites before opting in.")
    Exit Sub
End If

'  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.
Dim credentials As New Chilkat.JsonObject
credentials.Strict = True
success = credentials.LoadFile("qa_data/aws/s3.json")
If (success <> True) Then
    Debug.WriteLine("Could not load private S3 credentials.")
    Exit Sub
End If

stringCompare.SetString(credentials.StringOf("access_key"))
Dim stringMatch1 As Boolean = stringCompare.ContentsEqual("",True)
If ((credentials.JsonTypeOf("access_key") <> 1) Or (stringMatch1 = True)) Then
    Debug.WriteLine("Missing or invalid access_key.")
    Exit Sub
End If

stringCompare.SetString(credentials.StringOf("secret_key"))
Dim stringMatch2 As Boolean = stringCompare.ContentsEqual("",True)
If ((credentials.JsonTypeOf("secret_key") <> 1) Or (stringMatch2 = True)) Then
    Debug.WriteLine("Missing or invalid secret_key.")
    Exit Sub
End If

Dim http As New Chilkat.Http
http.AwsAccessKey = credentials.StringOf("access_key")
http.AwsSecretKey = credentials.StringOf("secret_key")
If (credentials.HasMember("session_token") = True) Then
    stringCompare.SetString(credentials.StringOf("session_token"))
    Dim stringMatch3 As Boolean = stringCompare.ContentsEqual("",True)
    If ((credentials.JsonTypeOf("session_token") <> 1) Or (stringMatch3 = True)) Then
        Debug.WriteLine("session_token must be a nonempty string when supplied.")
        Exit Sub
    End If

    http.AwsSessionToken = credentials.StringOf("session_token")
End If

'  Current Chilkat uses SigV4 by default. Do not select deprecated SigV2.
'  Set the actual bucket region, not the caller's location.
Dim region As String = "us-west-2"
http.AwsRegion = region
Dim endpoint As New 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.
Dim bucketName As String = "your-bucket-name"
'  A leading slash is part of a key. Do not add one to imitate a file path.
Dim objectName As String = "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.
Dim keyPath As New Chilkat.StringBuilder
keyPath.Append(http.UrlEncode(objectName))
Dim slashCount As Integer = keyPath.ReplaceNoCase("%2f","/")
Dim encodedKey As String = keyPath.GetAsString()
http.SetRequestHeader("x-amz-acl","public-read")
success = http.S3_UploadFile("qa_data/jpg/seahorse.jpg","image/jpeg",bucketName,encodedKey)
If (success <> True) Then
    Debug.WriteLine("Request failed (transport or S3 error). HTTP status: " & http.LastStatus)
    '  Inspect LastErrorText privately. Do not log credentials or signed URLs.
    Exit Sub
End If

If (http.LastStatus <> 200) Then
    Debug.WriteLine("Unexpected HTTP status: " & http.LastStatus)
    Exit Sub
End If

Debug.WriteLine("File upload succeeded.")