SDK 使用示例

2026-03-17 17:19

存储 SDK 提供便捷的 API 封装,帮助开发者快速集成。以下以 Python SDK 为例演示基本用法。
安装

bash
pip install smartstorage-sdk

初始化

python
from smartstorage import Client
client = Client(
    host="192.168.1.100",
    port=5000,
    api_key="YOUR_API_KEY"
)

文件上传

python
client.upload("local_file.txt", "/远程目录/file.txt", callback=progress_callback)

文件下载

python
client.download("/远程目录/file.txt", "local_file.txt")

列出目录

python
items = client.listdir("/远程目录")
for item in items:
    print(item.name, item.size, item.modified)

分享链接

python
link = client.share("/远程目录/file.txt", expire_days=7, password="123456")
print(link.url)

监听事件

python
def on_file_created(path):
    print(f"文件创建: {path}")

client.watch("/监控目录", on_file_created)

详细 API 参考请查阅 SDK 文档。示例代码可在 GitHub 仓库获取。

相关新闻