删除文件
通过 DELETE /v1/objects 从 Blob Storage 删除一个文件,或每个请求最多 100 个文件,批量删除时返回每个文件的结果。
DELETE
/
v1
/
objects
curl --request DELETE \
--url 'https://blob.squarecloud.app/v1/objects' \
--header 'Authorization: YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{ "object": "pub/3155597145698959364/images/logo_mugws5c0-9f86d081884c7d659a2feaa0c55ad015.png" }'
curl --request DELETE \
--url 'https://blob.squarecloud.app/v1/objects' \
--header 'Authorization: YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
"objects": [
"pub/3155597145698959364/images/logo_mugws5c0-9f86d081884c7d659a2feaa0c55ad015.png",
"prv/3155597145698959364/images/draft_mugws5c0-1b4f0e9851971998e732078544c96b36.png",
"pub/3155597145698959364/images/old.png"
]
}'
const response = await fetch('https://blob.squarecloud.app/v1/objects', {
method: 'DELETE',
headers: {
Authorization: 'YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({ objects: ids.slice(0, 100) }),
});
{
"status": "success"
}
{
"status": "success",
"response": {
"deleted": [
"pub/3155597145698959364/images/logo_mugws5c0-9f86d081884c7d659a2feaa0c55ad015.png",
"prv/3155597145698959364/images/draft_mugws5c0-1b4f0e9851971998e732078544c96b36.png"
],
"not_found": ["pub/3155597145698959364/images/old.png"],
"failed": []
}
}
删除操作会删除一个文件,或在单个请求中删除最多 100 个文件。删除是即时且不可撤回的:文件会停止分发,其占用的空间会从你的配额中释放。需要
blob:write scope。删除不需要有效的计划,因此你随时都可以清理文件。
- 单个 id(
object,或只含一项的objects):删除成功时返回200,文件不存在时返回404 OBJECT_NOT_FOUND。 - 两个或更多 id(
objects):始终返回200并附带每个文件的结果,因此某个文件不存在不会导致其余文件失败。重复的 id 只计一次。
400 INVALID_OBJECT 失败,此时不会删除任何内容。要查找 id,请使用对象列表。
参数
string
要删除的文件的 id。发送
object 或 objects 之一。string[]
单个请求中要删除的最多 100 个 id。
速率限制
每 10 秒 1000 个文件,按文件计数:一批 100 个计为 100。超出后账户会被短暂封禁(
RATE_LIMITED,429)。响应
string
成功为 “success”,否则为 “error”。
object
curl --request DELETE \
--url 'https://blob.squarecloud.app/v1/objects' \
--header 'Authorization: YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{ "object": "pub/3155597145698959364/images/logo_mugws5c0-9f86d081884c7d659a2feaa0c55ad015.png" }'
curl --request DELETE \
--url 'https://blob.squarecloud.app/v1/objects' \
--header 'Authorization: YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
"objects": [
"pub/3155597145698959364/images/logo_mugws5c0-9f86d081884c7d659a2feaa0c55ad015.png",
"prv/3155597145698959364/images/draft_mugws5c0-1b4f0e9851971998e732078544c96b36.png",
"pub/3155597145698959364/images/old.png"
]
}'
const response = await fetch('https://blob.squarecloud.app/v1/objects', {
method: 'DELETE',
headers: {
Authorization: 'YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({ objects: ids.slice(0, 100) }),
});
{
"status": "success"
}
{
"status": "success",
"response": {
"deleted": [
"pub/3155597145698959364/images/logo_mugws5c0-9f86d081884c7d659a2feaa0c55ad015.png",
"prv/3155597145698959364/images/draft_mugws5c0-1b4f0e9851971998e732078544c96b36.png"
],
"not_found": ["pub/3155597145698959364/images/old.png"],
"failed": []
}
}
错误
| 代码 | HTTP | 触发情况 |
|---|---|---|
INVALID_BODY | 400 | 请求体缺失或不是 JSON 对象。 |
INVALID_OBJECT | 400 | 没有发送任何 id,或某个 id 格式错误或不属于你。 |
TOO_MANY_OBJECTS | 400 | 超过 100 个 id。 |
OBJECT_NOT_FOUND | 404 | 文件不存在(单个文件)。 |
RATE_LIMITED | 429 | 10 秒内删除超过 1000 个文件。 |
DELETE_FAILED | 500 | 存储失败,文件可能仍然存在。请重试。 |
相关内容
- Blob SDK:
blob.delete()
⌘I
curl --request DELETE \
--url 'https://blob.squarecloud.app/v1/objects' \
--header 'Authorization: YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{ "object": "pub/3155597145698959364/images/logo_mugws5c0-9f86d081884c7d659a2feaa0c55ad015.png" }'
curl --request DELETE \
--url 'https://blob.squarecloud.app/v1/objects' \
--header 'Authorization: YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
"objects": [
"pub/3155597145698959364/images/logo_mugws5c0-9f86d081884c7d659a2feaa0c55ad015.png",
"prv/3155597145698959364/images/draft_mugws5c0-1b4f0e9851971998e732078544c96b36.png",
"pub/3155597145698959364/images/old.png"
]
}'
const response = await fetch('https://blob.squarecloud.app/v1/objects', {
method: 'DELETE',
headers: {
Authorization: 'YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({ objects: ids.slice(0, 100) }),
});
{
"status": "success"
}
{
"status": "success",
"response": {
"deleted": [
"pub/3155597145698959364/images/logo_mugws5c0-9f86d081884c7d659a2feaa0c55ad015.png",
"prv/3155597145698959364/images/draft_mugws5c0-1b4f0e9851971998e732078544c96b36.png"
],
"not_found": ["pub/3155597145698959364/images/old.png"],
"failed": []
}
}

