All Products
Search
Document Center

Lindorm:Develop applications using the S3 Java API

Last Updated:Aug 21, 2026

This topic provides instructions and code examples on how to use the S3 Java API to connect to and access Lindorm.

Prerequisites

  • A JDK 1.8 or later Java environment is required.

  • You have obtained the S3-compatible Endpoint for the Lindorm wide table engine. For more information, see View connection addresses.

  • You have added the client IP address to the Lindorm whitelist. For more information, see Configure a whitelist.

Procedure

  1. Install the S3 Java SDK. Open the Eclipse client, create a project, and configure the Maven dependencies in the pom.xml file as follows:

    • Add the Maven dependency for Java SDK 1.x.

      <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk-s3</artifactId>
        <version>1.11.655</version>
      </dependency>
    • Add the Maven dependency for Java SDK 2.x.

      <dependency>
        <groupId>software.amazon.awssdk</groupId>
        <artifactId>aws-sdk-java</artifactId>
        <version>2.17.32</version>
      </dependency>
  2. In your project, enter the following code to connect to and access LindormTable.

Java SDK 1.x code examples

  • Create a connection

    String s3Endpoint = "http://ld-bp17j28j2y7pm****-proxy-blob.lindorm.rds.aliyuncs.com:9053"; // The S3-compatible endpoint for LindormTable
    String bucketName = "testbucket";
    
    // Create a connection
    AmazonS3 client = AmazonS3ClientBuilder.standard()
            .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(s3Endpoint, null))
            .withPathStyleAccessEnabled(true)
            .withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials("AK", "SK")))
            .build();
    Note

    Replace the AK and SK fields in the example with the username and password for LindormTable. Store the password in an environment variable or configuration file. Do not use hard-coded passwords.

  • Bucket operations

    // Create a bucket
    Bucket bucket = client.createBucket(bucketName);
    
    // Check if the bucket exists
    HeadBucketResult result = client.headBucket(new HeadBucketRequest(bucketName));
    
    // List all buckets
    List<Bucket> buckets = client.listBuckets(new ListBucketsRequest());
    Note

    To create a new user and grant them permissions for bucket operations, see Create a user and S3 protocol permission management.

  • Object operations

    String content = "content";
    // Upload an object
    client.putObject(bucketName, key_name, content);
    
    // Read an object
    S3Object object = client.getObject(bucketName, keyName);
    
    // List all objects in the bucket
    // list v1
    ObjectListing objects = client.listObjects(bucketName);
    // list v2
    ListObjectsV2Result results = client.listObjectsV2(bucketName);
    
    // Delete an object
    client.deleteObject(bucketName, keyName);
    
    // Delete objects in a batch
    client.deleteObjects(new DeleteObjectsRequest(bucketName).withKeys(keyName));
  • Multipart upload operations

    // The file to upload
    File file = new File(filePath);
    long contentLength = file.length();
    long partSize = 5 * 1024 * 1024; // Set the part size to 5 MB
    
    List<PartETag> partETags = new ArrayList<PartETag>();
    
    // Initialize the multipart upload
    InitiateMultipartUploadRequest initRequest = new InitiateMultipartUploadRequest(bucketName, keyName);
    InitiateMultipartUploadResult initResponse = client.initiateMultipartUpload(initRequest);
    
    // Upload parts
    long filePosition = 0;
    for (int i = 1; filePosition < contentLength; i++) {
        partSize = Math.min(partSize, (contentLength - filePosition));
    
        // Upload part request
        UploadPartRequest uploadRequest = new UploadPartRequest()
            .withBucketName(bucketName)
            .withKey(keyName)
            .withUploadId(initResponse.getUploadId())
            .withPartNumber(i)
            .withFileOffset(filePosition)
            .withFile(file)
            .withPartSize(partSize);
    
        UploadPartResult uploadResult = client.uploadPart(uploadRequest);
        partETags.add(uploadResult.getPartETag());
    
        filePosition += partSize;
    }
    
    // Complete the multipart upload. The object is now visible.
    CompleteMultipartUploadRequest compRequest = new CompleteMultipartUploadRequest(bucketName, keyName,
                                                                                    initResponse.getUploadId(), partETags);
    client.completeMultipartUpload(compRequest);

Java SDK 2.x code examples

  • Create a connection

    String s3Endpoint = "http://ld-bp17j28j2y7pm****-proxy-blob.lindorm.rds.aliyuncs.com:9053"; // The S3-compatible endpoint for LindormTable
    String bucketName = "testbucket";
    
    // Create a connection
    AwsBasicCredentials creds = AwsBasicCredentials.create("AK", "SK");
    
    S3Client client = S3Client.builder()
        .serviceConfiguration(b -> b.checksumValidationEnabled(false))
        .region(Region.AP_EAST_1)
        .credentialsProvider(StaticCredentialsProvider.create(creds))
        .endpointOverride(new URI(s3Endpoint))
        .build();
    
    // Close the connection
    client.close();
    Note

    Replace the AK and SK fields in the example with the username and password for LindormTable. Store the password in an environment variable or configuration file. Do not use hard-coded passwords.

  • Bucket operations

    // Create a bucket
    S3Waiter s3Waiter = client.waiter();
    CreateBucketRequest bucketRequest = CreateBucketRequest.builder()
        .bucket(bucketName)
        .build();
    
    // Check if the bucket exists
    client.createBucket(bucketRequest);
    HeadBucketRequest bucketRequestWait = HeadBucketRequest.builder()
        .bucket(bucketName)
        .build();
    
    WaiterResponse<HeadBucketResponse> waiterResponse = s3Waiter.waitUntilBucketExists(bucketRequestWait);
    waiterResponse.matched().response().ifPresent(System.out::println);
    Note

    To create a new user and grant them permissions for bucket operations, see Create a user and S3 protocol permission management.

  • Object operations

    // Write an object
    PutObjectRequest putOb = PutObjectRequest.builder()
            .bucket(bucketName)
            .key(keyName)
            .build();
    
    PutObjectResponse response = client.putObject(putOb,
            RequestBody.fromString("content"));
    
    // Read an object
    GetObjectRequest objectRequest = GetObjectRequest
            .builder()
            .key(keyName)
            .bucket(bucketName)
            .build();
    
    ResponseBytes<GetObjectResponse> objectBytes = client.getObjectAsBytes(objectRequest);
        byte[] data = objectBytes.asByteArray();
    
    // List objects
    ListObjectsRequest listObjects = ListObjectsRequest
                        .builder()
                        .bucket(bucketName)
                        .build();
    
    ListObjectsResponse res = client.listObjects(listObjects);
    List<S3Object> objects = res.contents();
  • Multipart upload operations

    // Initialize the multipart upload
    CreateMultipartUploadRequest createMultipartUploadRequest = CreateMultipartUploadRequest.builder()
        .bucket(bucketName)
        .key(keyName)
        .build();
    
    CreateMultipartUploadResponse response = client.createMultipartUpload(createMultipartUploadRequest);
    String uploadId = response.uploadId();
    System.out.println(uploadId);
    
    // Upload part 1
    UploadPartRequest uploadPartRequest1 = UploadPartRequest.builder().bucket(bucketName).key(keyName)
        .uploadId(uploadId)
        .partNumber(1).build();
    String etag1 = client.uploadPart(uploadPartRequest1, RequestBody.fromString("content1")).eTag();
    CompletedPart part1 = CompletedPart.builder().partNumber(1).eTag(etag1).build();
    
    // Upload part 2
    UploadPartRequest uploadPartRequest2 = UploadPartRequest.builder().bucket(bucketName).key(keyName)
        .uploadId(uploadId)
        .partNumber(2).build();
    String etag2 = client.uploadPart(uploadPartRequest2, RequestBody.fromString("content2")).eTag();
    CompletedPart part2 = CompletedPart.builder().partNumber(2).eTag(etag2).build();
    
    // Complete the multipart upload. The object is now visible.
    CompletedMultipartUpload completedMultipartUpload = CompletedMultipartUpload.builder()
        .parts(part1, part2)
        .build();
    
    CompleteMultipartUploadRequest completeMultipartUploadRequest =
        CompleteMultipartUploadRequest.builder()
        .bucket(bucketName)
        .key(keyName)
        .uploadId(uploadId)
        .multipartUpload(completedMultipartUpload)
        .build();
    
    client.completeMultipartUpload(completeMultipartUploadRequest);