Blob 端点
Blob 对象上传
本文档全面介绍 SquareCloud Blob API 的 POST /v1/objects 端点。
curl --request POST \
--url 'https://blob.squarecloud.app/v1/objects?name=myfile&prefix=images&expire=30' \
--header 'Authorization: YOUR_API_KEY' \
--form 'file=@./myphone.png'
import fs from 'node:fs';
const form = new FormData();
form.append('file', new Blob([fs.readFileSync('./myphone.png')]), 'myphone.png');
const params = new URLSearchParams({
name: 'myfile',
prefix: 'images',
expire: '30',
});
const response = await fetch(`https://blob.squarecloud.app/v1/objects?${params}`, {
method: 'POST',
headers: { Authorization: 'YOUR_API_KEY' },
body: form,
});
import requests
with open('myphone.png', 'rb') as f:
response = requests.post(
'https://blob.squarecloud.app/v1/objects',
headers={'Authorization': 'YOUR_API_KEY'},
params={'name': 'myfile', 'prefix': 'images', 'expire': 30},
files={'file': ('myphone.png', f, 'image/png')},
)
{
"status": "success",
"response": {
"id": "3155597145698959364/images/test_lxch4k7y-07ee.png",
"name": "test",
"prefix": "images",
"size": 416230,
"url": "https://public-blob.squarecloud.dev/3155597145698959364/images/test_lxch4k7y-07ee.png"
}
}
使用 FormData。(multipart/form-data)
表示文件名称的字符串。(不含扩展名)
必须符合 a 到 z、A 到 Z、0 到 9 以及 _ 的模式。(3 到 32 个字符)
必须符合 a 到 z、A 到 Z、0 到 9 以及 _ 的模式。(3 到 32 个字符)
表示文件前缀的字符串。
必须符合 a 到 z、A 到 Z、0 到 9 以及 _ 的模式。(3 到 32 个字符)
必须符合 a 到 z、A 到 Z、0 到 9 以及 _ 的模式。(3 到 32 个字符)
表示文件过期周期的数字,范围为 1 到 365 天。
如果需要安全哈希,请设为 true。
如果文件应设为自动下载,请设为 true。
速率限制与并发
上传需要付费套餐。
- Hobby 和 Standard 套餐限制为每秒 1 次上传。
- Pro 和 Enterprise 套餐不受每秒限制约束,取而代之的是最多可同时进行 4 次上传。
TOO_MANY_CONCURRENT_UPLOADS(429)。出于安全考虑,
.html 和 .svg 文件始终以下载方式提供(作为 application/octet-stream 提供),而不是内联渲染。响应
指示调用是否成功。成功为 “success”,否则为 “error”。
curl --request POST \
--url 'https://blob.squarecloud.app/v1/objects?name=myfile&prefix=images&expire=30' \
--header 'Authorization: YOUR_API_KEY' \
--form 'file=@./myphone.png'
import fs from 'node:fs';
const form = new FormData();
form.append('file', new Blob([fs.readFileSync('./myphone.png')]), 'myphone.png');
const params = new URLSearchParams({
name: 'myfile',
prefix: 'images',
expire: '30',
});
const response = await fetch(`https://blob.squarecloud.app/v1/objects?${params}`, {
method: 'POST',
headers: { Authorization: 'YOUR_API_KEY' },
body: form,
});
import requests
with open('myphone.png', 'rb') as f:
response = requests.post(
'https://blob.squarecloud.app/v1/objects',
headers={'Authorization': 'YOUR_API_KEY'},
params={'name': 'myfile', 'prefix': 'images', 'expire': 30},
files={'file': ('myphone.png', f, 'image/png')},
)
{
"status": "success",
"response": {
"id": "3155597145698959364/images/test_lxch4k7y-07ee.png",
"name": "test",
"prefix": "images",
"size": 416230,
"url": "https://public-blob.squarecloud.dev/3155597145698959364/images/test_lxch4k7y-07ee.png"
}
}
故障排查
- 400 状态码
- 401 状态码
- 403 状态码
- 409 状态码
- 413 状态码
- 429 状态码
- 500 状态码
对象相关
// The provided object name is invalid.
// Must adhere to the a to z, A to Z, 0 to 9, and _ pattern.
{
"status": "error",
"code": "INVALID_OBJECT_NAME"
}
// The provided object prefix is invalid.
// Must adhere to the a to z, A to Z, 0 to 9, and _ pattern.
{
"status": "error",
"code": "INVALID_OBJECT_PREFIX"
}
// The provided expiration value for the object is invalid.
// Must be a number ranging from 1 to 365. (value in days).
{
"status": "error",
"code": "INVALID_OBJECT_EXPIRE"
}
// The provided security hash boolean is invalid.
// Just set to true or false. 😅
{
"status": "error",
"code": "INVALID_OBJECT_SECURITY_HASH"
}
// The provided auto-download boolean is invalid.
// Just set to true or false. 😅
{
"status": "error",
"code": "INVALID_STORAGE_AUTO_DOWNLOAD"
}
文件相关
当前文件大小上限为 100MB。未来我们计划将其提升至 10GB。目前受技术和负载均衡的限制,上限为 100MB。
// The provided file is invalid.
{
"status": "error",
"code": "INVALID_FILE"
}
// The provided file type is invalid.
{
"status": "error",
"code": "INVALID_FILETYPE"
}
// The file size is too small (< 1kb).
{
"status": "error",
"code": "FILE_TOO_SMALL"
}
未授权
// The API key is missing or invalid. Set a valid key in the Authorization header.
// Also returned when the account is on the free plan — uploading requires a paid plan.
{
"status": "error",
"code": "ACCESS_DENIED"
}
存储配额超限
// You have exceeded your storage quota. Delete some files or upgrade your plan.
{
"status": "error",
"code": "STORAGE_QUOTA_EXCEEDED"
}
无效的内容类型
// This route only accepts multipart/form-data requests.
{
"status": "error",
"code": "INVALID_CONTENT_TYPE"
}
载荷过大
当前文件大小上限为 100MB。
// The uploaded file exceeds the maximum allowed size of 100 MB.
{
"status": "error",
"code": "PAYLOAD_TOO_LARGE"
}
触发速率限制
// Per-second upload limit reached (Hobby/Standard: max 1 upload per second).
{
"status": "error",
"code": "RATELIMIT"
}
// Too many simultaneous uploads (max 4 in progress at a time per account).
{
"status": "error",
"code": "TOO_MANY_CONCURRENT_UPLOADS"
}
上传失败
// Failed to upload object to storage. Please try again later.
{
"status": "error",
"code": "UPLOAD_FAILED"
}
⌘I
curl --request POST \
--url 'https://blob.squarecloud.app/v1/objects?name=myfile&prefix=images&expire=30' \
--header 'Authorization: YOUR_API_KEY' \
--form 'file=@./myphone.png'
import fs from 'node:fs';
const form = new FormData();
form.append('file', new Blob([fs.readFileSync('./myphone.png')]), 'myphone.png');
const params = new URLSearchParams({
name: 'myfile',
prefix: 'images',
expire: '30',
});
const response = await fetch(`https://blob.squarecloud.app/v1/objects?${params}`, {
method: 'POST',
headers: { Authorization: 'YOUR_API_KEY' },
body: form,
});
import requests
with open('myphone.png', 'rb') as f:
response = requests.post(
'https://blob.squarecloud.app/v1/objects',
headers={'Authorization': 'YOUR_API_KEY'},
params={'name': 'myfile', 'prefix': 'images', 'expire': 30},
files={'file': ('myphone.png', f, 'image/png')},
)
{
"status": "success",
"response": {
"id": "3155597145698959364/images/test_lxch4k7y-07ee.png",
"name": "test",
"prefix": "images",
"size": 416230,
"url": "https://public-blob.squarecloud.dev/3155597145698959364/images/test_lxch4k7y-07ee.png"
}
}

