跳转到主要内容
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"
    }
}
Authorization
string
必填
你账户的 API 密钥。你可以在账户设置中找到它。
file
file
必填
使用 FormData。(multipart/form-data)
name
string
必填
表示文件名称的字符串。(不含扩展名)
必须符合 a 到 z、A 到 Z、0 到 9 以及 _ 的模式。(3 到 32 个字符)
prefix
string
表示文件前缀的字符串。
必须符合 a 到 z、A 到 Z、0 到 9 以及 _ 的模式。(3 到 32 个字符)
expire
number
表示文件过期周期的数字,范围为 1 到 365 天。
security_hash
boolean
如果需要安全哈希,请设为 true。
auto_download
boolean
如果文件应设为自动下载,请设为 true。

速率限制与并发

上传需要付费套餐。
  • HobbyStandard 套餐限制为每秒 1 次上传
  • ProEnterprise 套餐受每秒限制约束,取而代之的是最多可同时进行 4 次上传
在所有付费套餐中,一个账户最多可同时进行 4 次上传。当已有 4 次上传仍在进行时再启动一次上传,将返回 TOO_MANY_CONCURRENT_UPLOADS(429)。
出于安全考虑,.html.svg 文件始终以下载方式提供(作为 application/octet-stream 提供),而不是内联渲染。

响应

status
string
指示调用是否成功。成功为 “success”,否则为 “error”。
response
object
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"
    }
}

故障排查

对象相关

// 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"
}