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

Torch Object Storage

Copy page
Download PDF
Vector bucket
GetVectorBucketPolicy(TOS Vectors Node.js SDK)
Copy page
Download PDF
GetVectorBucketPolicy(TOS Vectors Node.js SDK)
The getVectorBucketPolicy interface queries the policy of a vector bucket. This article demonstrates how to use the getVectorBucketPolicy interface in the TOS Vectors Node.js SDK to perform this operation.​
Notes​
  • To prevent key leakage, this example code 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 Node.js SDK supports using temporary access credentials and offers timeout mechanisms, retry strategies, and other flexible settings to enhance application security based on your 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 need to execute the getVectorBucketPolicy operation using a subaccount, the main account must grant the following permissions to the subaccount via IAM Policy and Bucket Policy:​
tosvectors:GetVectorBucketPolicy​
Code example​
Query the bucket policy of the vector bucket​
​
// Query vector bucket policy​
​
import {​
TosVectorsClient,​
TosClientError,​
TosServerError,​
} from "@volcengine/tos-sdk";​
​
// Retrieve authentication information and configuration from environment variables​
const client = new TosVectorsClient({​
accessKeyId: process.env["TOS_ACCESS_KEY"], // TOS_ACCESS_KEY: your Access Key ID​
accessKeySecret: process.env["TOS_SECRET_KEY"], // TOS_SECRET_KEY: your Secret Key​
region: 'Provide your region',​
endpoint: 'Provide your vector endpoint',​
});​
​
// Read vector bucket name and account ID​
const vectorBucketName = 'Provide your vector bucket name'; ​
const accountId = process.env["TOS_ACCOUNT_ID"]; // TOS_ACCOUNT_ID: your account ID​
​
/**​
* Handle possible errors during SDK calls.​
*@paramerror caught error object​
*/​
function handleError(error: Error) {​
if (error instanceof TosClientError) {​
// client-side error, usually parameter error or network issue​
console.log("Client Error:");​
console.log(" Message:", error.message);​
if (error.stack) {​
console.log(" Stack:", error.stack);​
}​
} else if (error instanceof TosServerError) {​
// server-side error, indicates request delivered but processing failed​
console.log("Server Error:");​
console.log(" Request ID:", error.requestId);​
console.log(" Status Code:", error.statusCode);​
console.log(" Code:", error.code);​
console.log(" Message:", error.message);​
console.log(" Headers:", error.headers);​
} else {​
// other unknown errors​
console.log("Unexpected Error:");​
console.log(" Message:", error.message);​
}​
}​
​
async function main() {​
try {​
// 2. call getVectorBucketPolicy interface​
const result = await client.getVectorBucketPolicy({​
vectorBucketName,​
accountId: accountId,​
});​
​
// 3. print general response information​
console.log("The request has been successfully returned:");​
console.log(" Request ID:", result.requestId);​
console.log(" Status Code:", result.statusCode);​
console.log(" Headers:", result.headers);​
​
// 4. print policy details​
const policy = result.data;​
if (!policy) {​
console.log("No Policy data was retrieved.");​
return;​
}​
​
console.log("Basic information of the policy:");​
console.log(" Version:", policy.Version);​
​
const statements = policy.Statement || [];​
if (!Array.isArray(statements) || statements.length === 0) {​
console.log(" The current policy does not contain any statements.");​
return;​
}​
​
console.log("Statement list (Statements):");​
statements.forEach((statement: any, index: number) => {​
console.log(` [Statement ${index + 1}]`);​
if (statement.Sid !== undefined) {​
console.log(" Sid:", statement.Sid);​
}​
console.log(" Effect:", statement.Effect);​
​
const actions = statement.Action;​
if (Array.isArray(actions)) {​
console.log(" Action:", actions.join(", "));​
} else if (actions !== undefined) {​
console.log(" Action:", actions);​
}​
​
const principal = statement.Principal;​
if (Array.isArray(principal)) {​
console.log(" Principal:", principal.join(", "));​
} else if (​
principal !== null &&​
principal !== undefined &&​
typeof principal === "object"​
) {​
console.log(" Principal:", JSON.stringify(principal, null, 2));​
} else if (principal !== undefined) {​
console.log(" Principal:", principal);​
}​
​
const resource = statement.Resource;​
if (Array.isArray(resource)) {​
console.log(" Resource:", resource.join(", "));​
} else if (resource !== undefined) {​
console.log(" Resource:", resource);​
}​
});​
} catch (error: any) {​
handleError(error);​
}​
}​
​
main();​
​
​
Related documentation​
For the API documentation on GetVectorBucketPolicy, see GetVectorBucketPolicy.​
​
Last updated: 2026.02.06 18:01:45