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

Torch Object Storage

Copy page
Download PDF
Vector bucket
GetVectorBucketPolicy(TOS Vectors Java SDK)
Copy page
Download PDF
GetVectorBucketPolicy(TOS Vectors Java SDK)
The getVectorBucketPolicy interface retrieves the vector policy of a Bucket. This article explains how to query the vector policy using the getVectorBucketPolicy interface of the TOS Vectors Java SDK.​
Notes​
  • To prevent key leakage, the sample code in this article reads the 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 Configure Long-Term Access Credentials.​
  • The TOS Vectors Java SDK supports using temporary access credentials. It also supports configuring timeout mechanisms, retry policies, and other features, which you can flexibly set according to business needs to enhance application security. 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 to use a sub-account to perform the getVectorBucketPolicy operation, the main account must grant the following permissions to the sub-account through IAM policies and bucket policies:​
tosvectors:GetVectorBucketPolicy​
Code example​
Query the vector bucket Policy​
​
// Query the policy of the vector bucket.​
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.GetVectorBucketPolicyInput;​
import com.volcengine.tos.model.vectors.GetVectorBucketPolicyOutput;​
​
public class GetVectorBucketPolicyExample {​
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");​
String accountID = System.getenv("TOS_ACCOUNT_ID");​
​
// Fill in BucketName.​
String bucketName = 'Provide your bucket name';​
​
// Initialize client.​
TOSVectors client = new TOSVectorsClientBuilder().build(region, endpoint, accessKey, secretKey);​
​
try {​
// Create input parameters for querying vector bucket policy.​
GetVectorBucketPolicyInput input = GetVectorBucketPolicyInput.builder()​
.vectorBucketName(bucketName) // Set the vector bucket name.​
.accountId(accountID) // Set account ID​
.build();​
​
// Call the API for querying vector bucket policy.​
GetVectorBucketPolicyOutput output = client.getVectorBucketPolicy(input);​
​
// Print request information and policy content.​
System.out.println("RequestID: " + output.getRequestInfo().getRequestId());​
System.out.println("StatusCode: " + output.getRequestInfo().getStatusCode());​
System.out.println("Vector Bucket Policy: " + output.getPolicy());​
​
} catch (TosClientException e) {​
// Operation failed, caught Client exception. Generally, it is a request parameter error, 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 API documentation on GetVectorBucketPolicy, see GetVectorBucketPolicy.​
Last updated: 2026.02.06 18:01:47