You need to enable JavaScript to run this app.
Torch Object Storage

Torch Object Storage

Copy page
Download PDF
Vector bucket
ListVectorBuckets(TOS Vectors Java SDK)
Copy page
Download PDF
ListVectorBuckets(TOS Vectors Java SDK)
the listVectorBuckets interface lists vector buckets. this article explains how to use the listVectorBuckets interface in TOS Vectors Java SDK to list vector buckets and retrieve bucket metadata.​
Notes​
  • to prevent key leakage, the sample code reads Access Key ID and Secret Access Key from environment variables. therefore, before using the SDK, you need to configure long-term access credentials. for details, see configuring long-term access credentials.​
  • tos vectors java sdk supports using temporary access credentials; it also supports timeout settings, retry policies, and other mechanisms. you can configure these flexibly to enhance application security based on business needs. for details, see common configuration scenarios.​
Permissions required​
the main account has all permissions by default, but IAM users have no permissions by default. if you want a sub-account to perform the listVectorBuckets operation, the main account must grant the following permissions to the sub-account via IAM policies and bucket policies:​
tosvectors:ListVectorBuckets​
Code example​
List basic operations of vector buckets​
​
// List the basic usage of vector buckets​
import com.volcengine.tos.TOSVectorsClientBuilder;​
import com.volcengine.tos.TOSVectors;​
import com.volcengine.tos.TosClientException;​
import com.volcengine.tos.TosServerException;​
import com.volcengine.tos.model.vectors.ListVectorBucketsInput;​
import com.volcengine.tos.model.vectors.ListVectorBucketsOutput;​
import com.volcengine.tos.model.vectors.VectorBucket;​
​
public class ListVectorBucketsExample {​
public static void main(String[] args) {​
String endpoint = 'Provide your endpoint';​
String region = 'Provide your region';​
String accessKey = System.getenv("TOS_ACCESS_KEY");​
String secretKey = System.getenv("TOS_SECRET_KEY");​
​
// Initialize client.​
TOSVectors client = new TOSVectorsClientBuilder().build(region, endpoint, accessKey, secretKey);​
​
try {​
// Create list vector bucket request.​
ListVectorBucketsInput input = ListVectorBucketsInput.builder().build();​
​
// Call the List Vector Buckets API.​
ListVectorBucketsOutput output = client.listVectorBuckets(input);​
​
System.out.println("RequestID: " + output.getRequestInfo().getRequestId());​
System.out.println("StatusCode: " + output.getRequestInfo().getStatusCode());​
​
// Print vector bucket list information.​
if (output.getVectorBuckets() != null && !output.getVectorBuckets().isEmpty()) {​
System.out.println("Number of vector buckets: " + output.getVectorBuckets().size());​
for (VectorBucket bucket : output.getVectorBuckets()) {​
System.out.println("Vector bucket name: " + bucket.getVectorBucketName());​
System.out.println("Project name: " + bucket.getProjectName());​
System.out.println("Vector bucket TRN: " + bucket.getVectorBucketTrn());​
System.out.println("Creation time: " + bucket.getCreationTime());​
System.out.println("---");​
}​
} else {​
System.out.println("There are currently no vector buckets");​
}​
​
} catch (TosClientException e) {​
// Operation failed, caught Client exception. Generally, it is due to incorrect request parameters, and in this case, the request was not sent.​
System.out.println("Operation failed");​
System.out.println("Message: " + e.getMessage());​
if (e.getCause() != null) {​
e.getCause().printStackTrace();​
}​
} catch (TosServerException e) {​
// Operation failed, server exception captured, and detailed error information returned from the server can be obtained.​
System.out.println("Operation failed");​
System.out.println("StatusCode: " + e.getStatusCode());​
System.out.println("Code: " + e.getCode());​
System.out.println("Message: " + e.getMessage());​
System.out.println("RequestID: " + e.getRequestID());​
} catch (Throwable t) {​
// As a fallback to catch other exceptions, it generally won't execute here.​
System.out.println("Operation failed");​
System.out.println("unexpected exception, message: " + t.getMessage());​
}​
}​
}​
​
Paginate vector buckets listing​
​
// Paginated listing of vector buckets.​
import com.volcengine.tos.TOSVectorsClientBuilder;​
import com.volcengine.tos.TOSVectors;​
import com.volcengine.tos.TosClientException;​
import com.volcengine.tos.TosServerException;​
import com.volcengine.tos.model.vectors.ListVectorBucketsInput;​
import com.volcengine.tos.model.vectors.ListVectorBucketsOutput;​
import com.volcengine.tos.model.vectors.VectorBucket;​
import java.util.ArrayList;​
import java.util.List;​
​
public class ListVectorBucketsExample2 {​
public static void main(String[] args) {​
String endpoint = 'Provide your endpoint';​
String region = 'Provide your region';​
String accessKey = System.getenv("TOS_ACCESS_KEY");​
String secretKey = System.getenv("TOS_SECRET_KEY");​
​
// Initialize client.​
TOSVectors client = new TOSVectorsClientBuilder().build(region, endpoint, accessKey, secretKey);​
​
try {​
// Paginate and list vector buckets, displaying 2 per page.​
int maxResultsPerPage = 2;​
String nextToken = null;​
int pageCount = 0;​
int totalBucketCount = 0;​
​
do {​
pageCount++;​
​
// Build a pagination request.​
ListVectorBucketsInput.Builder inputBuilder = ListVectorBucketsInput.builder()​
.maxResults(maxResultsPerPage);​
​
// If it is not the first page, set nextToken.​
if (nextToken != null) {​
inputBuilder.nextToken(nextToken);​
}​
​
ListVectorBucketsInput input = inputBuilder.build();​
​
// Call the list vector buckets API.​
ListVectorBucketsOutput output = client.listVectorBuckets(input);​
​
System.out.println("Page " + pageCount + ":");​
System.out.println("RequestID: " + output.getRequestInfo().getRequestId());​
System.out.println("StatusCode: " + output.getRequestInfo().getStatusCode());​
​
// Process the vector buckets on the current page.​
if (output.getVectorBuckets() != null && !output.getVectorBuckets().isEmpty()) {​
int currentPageCount = output.getVectorBuckets().size();​
totalBucketCount += currentPageCount;​
System.out.println("Number of vector buckets on the current page: " + currentPageCount);​
​
for (VectorBucket bucket : output.getVectorBuckets()) {​
System.out.println(" Vector bucket name: " + bucket.getVectorBucketName());​
System.out.println(" Project name: " + bucket.getProjectName());​
System.out.println(" Creation time: " + bucket.getCreationTime());​
}​
} else {​
System.out.println("There are no vector buckets on the current page");​
}​
​
// Get the token for the next page.​
nextToken = output.getNextToken();​
System.out.println("Is there a next page: " + (nextToken != null ? "Yes" : "No"));​
System.out.println("---");​
​
} while (nextToken != null); // Continue paging when nextToken exists​
​
System.out.println("Pagination listing completed");​
System.out.println("Total pages: " + pageCount);​
System.out.println("Total number of vector buckets: " + totalBucketCount);​
​
} catch (TosClientException e) {​
// Operation failed, caught a Client exception. Generally, it is due to incorrect request parameters, and in this case, the request was not sent.​
System.out.println("Operation failed");​
System.out.println("Message: " + e.getMessage());​
if (e.getCause() != null) {​
e.getCause().printStackTrace();​
}​
} catch (TosServerException e) {​
// Operation failed, server exception captured, and detailed error information returned from the server can be obtained.​
System.out.println("Operation failed");​
System.out.println("StatusCode: " + e.getStatusCode());​
System.out.println("Code: " + e.getCode());​
System.out.println("Message: " + e.getMessage());​
System.out.println("RequestID: " + e.getRequestID());​
} catch (Throwable t) {​
// As a fallback to catch other exceptions, it generally won't execute here.​
System.out.println("Operation failed");​
System.out.println("unexpected exception, message: " + t.getMessage());​
}​
}​
}​
​
Related documentation​
For the API documentation of ListVectorBuckets, see ListVectorBuckets.​
Last updated: 2026.02.06 18:01:48