Skip to navigation

Java

Upload, download and share files from Java with the AWS SDK for Java 2.x.

The AWS SDK for Java 2.x works with Zata. Point the S3 client at the Zata endpoint, and you can use the normal S3 calls from Java, including Spring Boot apps.

Tested with the AWS SDK for Java 2.46.7 (software.amazon.awssdk:s3) on Java 21 on Zata in October 2026.

Before you start

Connection settings

SettingValue
endpointOverridehttps://idr01.zata.ai for Indore, https://bom01.zata.ai for Mumbai
regionRegion.US_EAST_1
Access key / Secret keyfrom Access Keys in the Zata console. The key must be from the same region as the bucket.
forcePathStyletrue
requestChecksumCalculation / responseChecksumValidationWHEN_REQUIRED

Add the SDK

<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId>
<version>2.46.7</version>
</dependency>

Create the client

Keep your keys out of the code. Put them in environment variables; the SDK reads them by itself:

export AWS_ACCESS_KEY_ID=YOUR_ACCESS_KEY
export AWS_SECRET_ACCESS_KEY=YOUR_SECRET_KEY

Then create the client. For a bucket in Mumbai, use https://bom01.zata.ai.

import java.net.URI;
import software.amazon.awssdk.core.checksums.RequestChecksumCalculation;
import software.amazon.awssdk.core.checksums.ResponseChecksumValidation;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3Client;
S3Client s3 = S3Client.builder()
.endpointOverride(URI.create("https://idr01.zata.ai"))
.region(Region.US_EAST_1)
.forcePathStyle(true)
.requestChecksumCalculation(RequestChecksumCalculation.WHEN_REQUIRED)
.responseChecksumValidation(ResponseChecksumValidation.WHEN_REQUIRED)
.build();

The two WHEN_REQUIRED lines are required. With the SDK’s default settings (version 2.30 and newer), every upload to Zata fails with XAmzContentSHA256Mismatch, even small files.

Upload, download and list files

import software.amazon.awssdk.core.sync.RequestBody;
import software.amazon.awssdk.services.s3.model.*;
// Upload
s3.putObject(PutObjectRequest.builder().bucket("my-bucket").key("hello.txt").build(),
RequestBody.fromString("hello from java"));
// Download
String text = s3.getObjectAsBytes(GetObjectRequest.builder().bucket("my-bucket").key("hello.txt").build())
.asUtf8String();
// Count the files in the bucket
int count = s3.listObjectsV2(ListObjectsV2Request.builder().bucket("my-bucket").build()).keyCount();

To upload a file from disk, use RequestBody.fromFile(Paths.get("myfile.txt")) (with import java.nio.file.Paths;).

List your buckets

s3.listBuckets().buckets().forEach(b -> System.out.println(b.name()));

A sub-user’s key gets an empty list here, even for buckets it can use. Use the bucket name directly.

A presigned URL lets someone download one file without keys, until the link expires.

import java.time.Duration;
import software.amazon.awssdk.services.s3.S3Configuration;
import software.amazon.awssdk.services.s3.presigner.S3Presigner;
import software.amazon.awssdk.services.s3.presigner.model.GetObjectPresignRequest;
try (S3Presigner presigner = S3Presigner.builder()
.endpointOverride(URI.create("https://idr01.zata.ai"))
.region(Region.US_EAST_1)
.serviceConfiguration(S3Configuration.builder().pathStyleAccessEnabled(true).build())
.build()) {
String url = presigner.presignGetObject(GetObjectPresignRequest.builder()
.signatureDuration(Duration.ofMinutes(10))
.getObjectRequest(GetObjectRequest.builder().bucket("my-bucket").key("hello.txt").build())
.build()).url().toString();
}

Anyone who has the link can use it until it expires, so share it only with the intended person.

Troubleshooting

ProblemFix
XAmzContentSHA256Mismatch on every uploadAdd the two WHEN_REQUIRED lines to the client. Or set the environment variables AWS_REQUEST_CHECKSUM_CALCULATION=when_required and AWS_RESPONSE_CHECKSUM_VALIDATION=when_required.
InvalidAccessKeyIdendpointOverride is missing (requests go to AWS), or the key is from the other region.
NoSuchBucketUse the endpoint of the region the bucket is in.
The bucket list is emptyA sub-user’s key cannot list buckets. Use the bucket name directly.

For other errors, see Large uploads and Wrong endpoint or region.