> For the complete documentation index, see [llms.txt](https://docs.unitlab.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.unitlab.ai/api-sdk-cli/zh/sdks/pattern-cloud-folder-to-project.md).

# 模式：从云存储到项目

用 Unitlab Python SDK 定时把云存储（S3、GCS、Azure）存储桶中的新录制数据导入项目，无需复制媒体文件，适合每晚自动入队标注。

当机器人或车队车辆把录制数据写入 S3、GCS 或 Azure，并需要一个每晚运行的任务把新数据加入标注队列时，请采用这种模式。

```python
import os
from unitlab import UnitlabClient

PREFIX = "fleet/cell-04/2026-11-21/"

client = UnitlabClient()
try:
    storage = client.cloud_storages.get(os.environ["CLOUD_STORAGE_ID"])
    project = client.projects.get(os.environ["PROJECT_ID"])

    paths = [entry.name for entry in storage.browse(prefix=PREFIX, project=project)
             if entry.type == "file" and entry.is_extension_allowed]
    if not paths:
        raise SystemExit("Nothing new")

    batch = project.import_cloud(storage, paths, fps=2.0)
    status = batch.wait(timeout=3600)
    print(f"Imported {status.completed} of {status.total}, {status.failed} failed")
finally:
    client.close()
```

若要导入整个前缀，可传入以 `/` 结尾的文件夹路径，而不是单个文件。每个前缀运行一次导入，并把 Batch Queue ID 记入任务日志，这样重新运行时就能检查哪些文件已经到达。

## 前提条件 <a href="#requirements" id="requirements"></a>

* 在应用中创建的云存储连接，并具备该存储桶的读取权限。
* 具备 **Manage cloud storage** 和 **Manage data** 权限的密钥。

## 相关内容 <a href="#related" id="related"></a>

[云存储](https://docs.unitlab.ai/api-sdk-cli/zh/sdks/cloud-storage.md) · [Batch Queue 与处理状态](https://docs.unitlab.ai/api-sdk-cli/zh/sdks/batch-queues-and-processing.md) · [CLI 自动化与退出行为](https://docs.unitlab.ai/api-sdk-cli/zh/clis/cli-automation-and-exit-behavior.md)
