此接口用于批量删除桶中的多个对象,每次最多能够删除 1000 条。
在开启版本控制的桶中,在调用 DeleteMultiObjects 接口来批量删除对象时,如果在 Delete 请求中未指定versionId,将插入删除标记。如果指定了versionId,将永久删除该对象的指定版本。
批量删除对象支持的响应方式可以通过quiet进行设置。quiet为false时,是指在返回响应时,不管对象是否删除成功都将删除结果包含在响应里;quiet为true时,是指在返回响应时,只返回删除失败的对象结果,没有返回的认为删除成功。
POST /?delete HTTP/1.1 Host: bucketname.tos-cn-beijing.volces.com Date: GMT Date Authorization: authorization string Content-MD5: md5 string { "Objects": [{ "Key": "obj1", "VersionId": "string" }], "Quiet": false }
该请求的公共请求消息头,请参见公共参数。
名称 | 位置 | 参数类型 | 是否必选 | 示例值 | 说明 |
|---|---|---|---|---|---|
delete | Query | String | 是 | - | 代表 DeleteMultipleObjects 请求的特殊标识。 |
Content-MD5 | Header | String | 是 | dgWRtDmbPCHa/IS1s7XxUg== | 将 DeleteMultipleObjects 的请求消息体经过 Base64MD5 加密后得到的字符串的值。 |
recursive | Query | String | 否 | true | 递归删除非空目录。取值为
注意 该参数仅支持在开启回收站功能的分层命名空间使用,回收站功能详情请参见回收站。 |
skipTrash | Query | String | 否 | true | 是否跳过回收站彻底删除,取值说明如下:
注意 该参数仅支持在开启回收站功能的分层命名空间使用,回收站功能详情请参见回收站。 |
名称 | 参数类型 | 是否必选 | 示例值 | 说明 |
|---|---|---|---|---|
Objects | Array | 是 | - | 待删除对象列表根节点。 |
Key | String | 是 | objectName | 待删除对象名。父节点为 Objects。 |
VersionId | String | 否 | 57AF1A32CECB56721267 | 待删除对象版本号。父节点为 Objects。 |
Quiet | Bool | 否 | false | 批删之后响应模式,取值说明如下:
|
该请求返回的公共响应消息头,请参见公共参数。
名称 | 参数类型 | 示例值 | 说明 |
|---|---|---|---|
Deleted | Array | - | 成功删除的结果信息列表。 |
Key | String | obj1 | 被删除的对象名。 |
DeleteMarker | Bool | true | 标识是否为删除标记。 |
DeleteMarkerVersionId | String | 43D62700044343044833 | 删除标记对应的版本 ID。 |
Error | Object | - | 删除失败结果列表。 |
Code | String | AccessDenied | 删除失败的错误码。 |
Message | String | Access Denied | 删除失败的错误消息。 |
TrashPath | String | .Trash/20250107070000/dir/ | 文件或者目录被移入回收站后的路径。 |
批量删除 obj1 和 obj2。
POST /?delete HTTP/1.1 Host: bucketname.tos-cn-beijing.volces.com Date: Fri, 30 Jul 2021 13:56:19 GMT Authorization: authorization string Content-MD5: md5 string { "Objects": [{ "Key": "obj1" }, { "Key": "obj2" }], "Quiet": false }
成功响应示例:
HTTP/1.1 200 OK Date: Fri, 30 Jul 2021 13:56:19 GMT Server: TosServer Content-Type: application/xml x-tos-id-2: 4fac130bee03002e-a444ed0 x-tos-request-id: 4fac130bee03002e-a444ed0 { "Deleted": [ { "Key": "obj2" }, { "Key": "obj1" } ] }
失败响应示例:
HTTP/1.1 400 Bad Request Date: Fri, 30 Jul 2021 13:56:52 GMT Server: TosServer x-tos-id-2: 4fac130bee240030-a444ed0 x-tos-request-id: 4fac130bee240030-a444ed0 { "Code": "BadDigest", "RequestId": "4d31430787b94d11b80b348122ff2290-ac1a1791", "HostId": "GFdpcBKxovJAtAdAQluzipAXqaRyDTc", "Message": "The Content-MD5 you specified did not match what we received." }
如果从多版本开启的桶中删除对象,未指定 VersionId,因此为其插入删除标记。
POST /?delete HTTP/1.1 Host: bucketname.tos-cn-beijing.volces.com Date: Fri, 30 Jul 2021 13:56:19 GMT Authorization: authorization string Content-MD5: md5 string { "Objects": [{ "Key": "obj1" }], "Quiet": false }
开启多版本的桶,未指定 VersionId,对象删除成功响应消息。
HTTP/1.1 200 OK Date: Fri, 30 Jul 2021 13:56:19 GMT Server: TosServer x-tos-id-2: 4fac130bee03002e-a444ed0 x-tos-request-id: 4fac130bee03002e-a444ed0 { "Deleted": [ { "Key": "obj1", "DeleteMarker": true, "DeleteMarkerVersionId": "581CAE50578790BEF9C2" } ] }
如果从多版本开启的桶中删除对象,指定 VersionId 删除。
POST /?delete HTTP/1.1 Host: bucketname.tos-cn-beijing.volces.com Date: Fri, 30 Jul 2021 13:56:19 GMT Authorization: authorization string Content-MD5: md5 string { "Objects": [{ "Key": "obj1", "VersionId": "581CAE10FC6325DEBC3F" }], "Quiet": false }
开启多版本的桶,指定 VersionId,对象删除成功响应消息。
HTTP/1.1 200 OK Date: Fri, 30 Jul 2021 13:56:19 GMT Server: TosServer x-tos-id-2: 4fac130bee03002e-a444ed0 x-tos-request-id: 4fac130bee03002e-a444ed0 { "Deleted": [ { "Key": "obj1", "DeleteMarker": true, "DeleteMarkerVersionId": "581CAE10FC6325DEBC3F" } ] }
该示例展示,批量删除对象,返回结果中同时包含成功和失败的对象。在如下示例中,该请求者没有删除对象 obj2 的权限。
POST /?delete HTTP/1.1 Host: bucketname.tos-cn-beijing.volces.com Date: Fri, 30 Jul 2021 13:56:19 GMT Authorization: authorization string Content-MD5: md5 string { "Objects": [{ "Key": "obj1" }, { "Key": "obj2" }], "Quiet": false }
响应消息中,Deleted 表示删除成功的对象,Error 表示删除失败的对象。
HTTP/1.1 200 OK Date: Fri, 30 Jul 2021 13:56:19 GMT Server: TosServer x-tos-id-2: 4fac130bee03002e-a444ed0 x-tos-request-id: 4fac130bee03002e-a444ed0 { "Deleted": [ { "Key": "obj1" } ], "Error": [ { "Code": "AccessDenied", "Message": "Access Denied", "Key": "obj2" } ] }
开启回收站后,携带 recursive=true 递归删除目录 dir1/ 和 dir2/,dir1/ 和 dir2/ 进入回收站,其在回收站中的路径分别为 .Trash/20250321073000/dir1/、.Trash/20250321073000/dir2/。
POST /?delete=&recursive=true HTTP/1.1 Host: bucketname.tos-cn-beijing.volces.com Date: Fri, 30 Jul 2021 13:56:19 GMT Authorization: authorization string Content-MD5: md5 string { "Objects": [{ "Key": "dir1/" }, { "Key": "dir2/" }], "Quiet": false }
HTTP/1.1 200 OK Date: Fri, 30 Jul 2021 13:56:19 GMT Server: TosServer Content-Type: application/xml x-tos-id-2: 4fac130bee03002e-a444ed0 x-tos-request-id: 4fac130bee03002e-a444ed0 { "Deleted": [ { "Key": "dir1/", "TrashPath": ".Trash/20250321073000/dir1/" }, { "Key": "dir2/", "TrashPath": ".Trash/20250321073000/dir2/" } ] }
开启回收站后,携带 skipTrash=true 跳过回收站删除文件 file1 和 file2,file1 和 file2 被彻底删除。
POST /?delete=&skipTrash=true HTTP/1.1 Host: bucketname.tos-cn-beijing.volces.com Date: Fri, 30 Jul 2021 13:56:19 GMT Authorization: authorization string Content-MD5: md5 string { "Objects": [{ "Key": "file1" }, { "Key": "file2" }], "Quiet": false }
HTTP/1.1 200 OK Date: Fri, 30 Jul 2021 13:56:19 GMT Server: TosServer Content-Type: application/xml x-tos-id-2: 4fac130bee03002e-a444ed0 x-tos-request-id: 4fac130bee03002e-a444ed0 { "Deleted": [ { "Key": "file1" }, { "Key": "file2" } ] }