跳到正文

存储

S3 兼容的存储桶与对象,支持预签名 URL。

概览

基础路径: /v1/storage
Python 命名空间: infra.storage
text
# Python
from infrai import infra

# TypeScript
import { InfraiClient } from "@infrai/sdk";
const client = new InfraiClient({ apiKey: process.env.INFRAI_API_KEY! });
// → client.storage

方法

storage.bucket.create

POST /v1/storage/buckets

在所选供应商与区域创建对象存储桶。

Python

python
infra.storage.bucket.create(bucket=..., vendor=None, region=None, acl=None)

TypeScript

typescript
client.storage.bucket.create(opts): Promise<Bucket>

参数

名称类型必填说明
bucketstring
必填
存储桶名称。
vendorstring可选固定使用某个供应商,而非自动路由。
regionstring可选存储区域。
acl"private" | "public"可选存储桶访问控制。

返回

Bucket { bucket, vendor, region, created_at, acl? }

示例

一次性前置(每个范例都假定已完成):

bash
pip install infrai
# one-time auth (no secret needed): anonymous account + trial, writes ~/.infrai/credentials
python -c "from infrai import infra; infra.activate()"
# returning user instead: export INFRAI_API_KEY=ifr_pk_proj_...
python
from infrai import infra

b = infra.storage.bucket.create(bucket="user-uploads", acl="private")
print("bucket:", b.get("bucket"), "| vendor:", b.get("vendor"))

storage.bucket.list

GET /v1/storage/buckets

列出你的存储桶。

Python

python
infra.storage.bucket.list()

TypeScript

typescript
client.storage.bucket.list(): Promise<{ items }>

返回

{ items: Bucket[] }

示例

一次性前置(每个范例都假定已完成):

bash
pip install infrai
# one-time auth (no secret needed): anonymous account + trial, writes ~/.infrai/credentials
python -c "from infrai import infra; infra.activate()"
# returning user instead: export INFRAI_API_KEY=ifr_pk_proj_...
python
from infrai import infra

for b in infra.storage.bucket.list().get("items", []):
    print(b.get("bucket"), b.get("region"))

storage.object.presign

POST /v1/storage/buckets/{bucket}/objects/{key}/presign

为上传或下载对象创建预签名 URL。

Python

python
infra.storage.object.presign(bucket=..., key=..., method="PUT", expires_seconds=None)

TypeScript

typescript
client.storage.object.presign(opts): Promise<PresignedUrl>

参数

名称类型必填说明
bucketstring
必填
存储桶名称。
keystring
必填
桶内的对象 key(路径)。
method"GET" | "PUT"可选预签名 URL 授权的 HTTP 方法。
expires_secondsnumber可选预签名 URL 有效时长(秒)。

返回

PresignedUrl { url, method, expires_at, headers? }

示例

一次性前置(每个范例都假定已完成):

bash
pip install infrai
# one-time auth (no secret needed): anonymous account + trial, writes ~/.infrai/credentials
python -c "from infrai import infra; infra.activate()"
# returning user instead: export INFRAI_API_KEY=ifr_pk_proj_...
python
from infrai import infra

# Presign a PUT, then upload bytes directly to the object store.
put = infra.storage.object.presign(
    bucket="demo",
    key="uploads/hello.txt",
    method="PUT",
    expires_seconds=600,
)
print("upload url:", put.get("url"))

storage.object.delete

DELETE /v1/storage/buckets/{bucket}/objects/{key}

从存储桶删除对象。

Python

python
infra.storage.object.delete(bucket=..., key=...)

TypeScript

typescript
client.storage.object.delete(opts): Promise<{ ok }>

参数

名称类型必填说明
bucketstring
必填
存储桶名称。
keystring
必填
桶内的对象 key(路径)。

返回

{ ok: boolean }

示例

一次性前置(每个范例都假定已完成):

bash
pip install infrai
# one-time auth (no secret needed): anonymous account + trial, writes ~/.infrai/credentials
python -c "from infrai import infra; infra.activate()"
# returning user instead: export INFRAI_API_KEY=ifr_pk_proj_...
python
from infrai import infra

res = infra.storage.object.delete(bucket="user-uploads", key="uploads/old.txt")
print("deleted:", res.get("ok"))