该接口用于列举桶中的未合并的对象,即列举分片上传任务。
列举分片上传任务前,您需要拥有 tos:ListBucketMultipartUploads
权限,具体操作,请参见 IAM 策略概述。
参数 | 描述 |
---|---|
delimiter | 对对象名称进行分组的字符。 |
encodingType | 对返回的内容进行编码并指定编码的类型。取值说明如下:
|
maxUploads | 返回分片上传任务的最大数量。默认值为 1000。 |
prefix | 用于指定列举返回对象的前缀名称。 |
keyMarker | 列举分片上传任务的起始位置。设定从该值之后按字母排序返回对象列表。通常为上次请求返回的 |
uploadIDMarker | 与 |
以下代码用于列举指定存储桶中最多 10 个未合并的分片上传任务。
// 导入 SDK, 当 TOS Node.JS SDK 版本小于 2.5.2 请把下方 TosClient 改成 TOS 导入 import { TosClient, TosClientError, TosServerError } from '@volcengine/tos-sdk'; // 创建客户端 const client = new TosClient({ accessKeyId: process.env['TOS_ACCESS_KEY'], accessKeySecret: process.env['TOS_SECRET_KEY'], region: "Provide your region", // 填写 Bucket 所在地域。以华北2(北京)为例,则 "Provide your region" 填写为 cn-beijing。 endpoint: "Provide your endpoint", // 填写域名地址 }); function handleError(error) { if (error instanceof TosClientError) { console.log('Client Err Msg:', error.message); console.log('Client Err Stack:', error.stack); } else if (error instanceof TosServerError) { console.log('Request ID:', error.requestId); console.log('Response Status Code:', error.statusCode); console.log('Response Header:', error.headers); console.log('Response Err Code:', error.code); console.log('Response Err Msg:', error.message); } else { console.log('unexpected exception, message: ', error); } } const bucketName = 'node-sdk-test-bucket'; async function main() { try { // 获取 bucket 中最多 10 个未完成任务 const { data } = await client.listMultipartUploads({ bucket: bucketName, maxKeys: 1000, }); console.log('Uploads.length:', data.Uploads.length); for (const upload of data.Uploads) { console.log('Object Key:', upload.Key); console.log('UploadID:', upload.UploadId); console.log('Owner:', upload.Owner); console.log('StorageClass:', upload.StorageClass); } } catch (error) { handleError(error); } } main();
以下代码用于列举指定存储桶指定前缀下的所有未合并的分片上传任务。
// 导入 SDK, 当 TOS Node.JS SDK 版本小于 2.5.2 请把下方 TosClient 改成 TOS 导入 import { TosClient, TosClientError, TosServerError } from '@volcengine/tos-sdk'; // 创建客户端 const client = new TosClient({ accessKeyId: process.env['TOS_ACCESS_KEY'], accessKeySecret: process.env['TOS_SECRET_KEY'], region: "Provide your region", // 填写 Bucket 所在地域。以华北2(北京)为例,则 "Provide your region" 填写为 cn-beijing。 endpoint: "Provide your endpoint", // 填写域名地址 }); function handleError(error) { if (error instanceof TosClientError) { console.log('Client Err Msg:', error.message); console.log('Client Err Stack:', error.stack); } else if (error instanceof TosServerError) { console.log('Request ID:', error.requestId); console.log('Response Status Code:', error.statusCode); console.log('Response Header:', error.headers); console.log('Response Err Code:', error.code); console.log('Response Err Msg:', error.message); } else { console.log('unexpected exception, message: ', error); } } const bucketName = 'node-sdk-test-bucket'; async function main() { try { // 列举指定前缀的所有多版本对象 const prefix = '*** Provide your object key prefix ***'; for (let truncated = true, keyMarker = '', uploadIdMarker = ''; truncated; ) { const { data } = await client.listMultipartUploads({ bucket: bucketName, maxUploads: 1000, prefix, keyMarker, uploadIdMarker, }); console.log('Uploads.length:', data.Uploads.length); for (const upload of data.Uploads) { console.log('Object Key:', upload.Key); console.log('UploadID:', upload.UploadId); console.log('Owner:', upload.Owner); console.log('StorageClass:', upload.StorageClass); } truncated = data.IsTruncated; keyMarker = data.NextKeyMarker; uploadIdMarker = data.NextUploadIdMarker; } } catch (error) { handleError(error); } } main();
以下代码用于列举制定存储桶未合并的所有分片上传任务。
// 导入 SDK, 当 TOS Node.JS SDK 版本小于 2.5.2 请把下方 TosClient 改成 TOS 导入 import { TosClient, TosClientError, TosServerError } from '@volcengine/tos-sdk'; // 创建客户端 const client = new TosClient({ accessKeyId: process.env['TOS_ACCESS_KEY'], accessKeySecret: process.env['TOS_SECRET_KEY'], region: "Provide your region", // 填写 Bucket 所在地域。以华北2(北京)为例,则 "Provide your region" 填写为 cn-beijing。 endpoint: "Provide your endpoint", // 填写域名地址 }); function handleError(error) { if (error instanceof TosClientError) { console.log('Client Err Msg:', error.message); console.log('Client Err Stack:', error.stack); } else if (error instanceof TosServerError) { console.log('Request ID:', error.requestId); console.log('Response Status Code:', error.statusCode); console.log('Response Header:', error.headers); console.log('Response Err Code:', error.code); console.log('Response Err Msg:', error.message); } else { console.log('unexpected exception, message: ', error); } } const bucketName = 'node-sdk-test-bucket'; async function main() { try { // 列举所有多版本对象 for (let truncated = true, keyMarker = '', uploadIdMarker = ''; truncated; ) { const { data } = await client.listMultipartUploads({ bucket: bucketName, maxUploads: 1000, keyMarker, uploadIdMarker, }); console.log('Uploads.length:', data.Uploads.length); for (const upload of data.Uploads) { console.log('Object Key:', upload.Key); console.log('UploadID:', upload.UploadId); console.log('Owner:', upload.Owner); console.log('StorageClass:', upload.StorageClass); } truncated = data.IsTruncated; keyMarker = data.NextKeyMarker; uploadIdMarker = data.NextUploadIdMarker; } } catch (error) { handleError(error); } } main();