---
sidebar:
  label: roboto.storage.file_service
  order: 4
title: roboto.storage.file_service
---
## Module Contents

### FileService

```python
class roboto.storage.file_service.FileService(
    roboto_client: Optional[roboto.http.RobotoClient] = None,
    object_store_registry: Optional[roboto.storage.object_store.StoreRegistry] = None,
)
```

`from roboto.storage import FileService`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/storage/file_service.py#L37-L240)

Service that uploads local files to Roboto and downloads files Roboto stores to local disk.

[`upload_files()`](/docs/reference/python-sdk/roboto/domain/datasets/dataset#roboto.domain.datasets.dataset.Dataset.upload_files), [`download()`](/docs/reference/python-sdk/roboto/domain/files/file#roboto.domain.files.file.File.download) and the other upload and download methods transfer files through it, so most code never calls it. It moves file contents directly to and from the object store that holds them, such as an S3 bucket, with temporary credentials Roboto issues.

**Parameters**

- **roboto_client** (`Optional[roboto.http.RobotoClient]`): Client to make requests to Roboto with. Defaults to one configured from the environment, by [`from_env()`](/docs/reference/python-sdk/roboto/http/roboto_client#roboto.http.roboto_client.RobotoClient.from_env).
- **object_store_registry** (`Optional[roboto.storage.object_store.StoreRegistry]`): Registry that picks the object store for a storage URI by its scheme. Defaults to [`StoreRegistry`](/docs/reference/python-sdk/roboto/storage/object_store/registry#roboto.storage.object_store.registry.StoreRegistry).

#### FileService.download()

```python
def download(
    files: collections.abc.Sequence[roboto.storage.download_session.DownloadableFile],
    association: roboto.association.Association,
    caller_org_id: Optional[str] = None,
    on_progress: Optional[roboto.storage.object_store.OnProgress] = None,
) -> None
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/storage/file_service.py#L168-L240)

Download files Roboto stores to local paths, retrying the files that fail.

Downloads the files one bucket at a time, with read credentials Roboto issues for `association`. A file that fails to download is tried again immediately, up to three attempts in all; files that succeeded are not downloaded again.

**Parameters**

- **files** (`collections.abc.Sequence[roboto.storage.download_session.DownloadableFile]`): Files to download, each with its bucket, its storage URI, and the local path to save it to.
- **association** (`roboto.association.Association`): Resource the files belong to, which Roboto issues the read credentials for.
- **caller_org_id** (`Optional[str]`): Organization to act in. Required when the caller belongs to more than one organization; otherwise the caller's only organization.
- **on_progress** (`Optional[roboto.storage.object_store.OnProgress]`): Function called with the number of bytes downloaded since its previous call. `None` reports no progress.

**Raises**

- [`RobotoNotFoundException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoNotFoundException): Roboto issues no credentials for a file's bucket, such as a bucket not registered with Roboto.
- `ExceptionGroup`: One or more files still failed after three attempts. It holds the last exception of each failed file. Files in buckets not yet reached are not downloaded.

**Returns**

- `None`

#### FileService.upload()

```python
def upload(
    files: collections.abc.Iterable[pathlib.Path],
    association: roboto.association.Association,
    destination_paths: collections.abc.Mapping[pathlib.Path, str] = {},
    batch_size: int = _DEFAULT_UPLOAD_BATCH_SIZE,
    device_id: Optional[str] = None,
    caller_org_id: Optional[str] = None,
    on_progress: Optional[roboto.storage.object_store.OnProgress] = None,
) -> dict[pathlib.Path, str]
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/storage/file_service.py#L60-L166)

Upload local files to a dataset or another resource, and return the ID of the file each one created.

The files upload in batches of `batch_size`. Each batch is one upload transaction, which Roboto completes before the next batch begins.

**Parameters**

- **files** (`collections.abc.Iterable[pathlib.Path]`): Local files to upload.
- **association** (`roboto.association.Association`): Resource to upload the files to: a dataset, device, device type, organization, or topic.
- **destination_paths** (`collections.abc.Mapping[pathlib.Path, str]`): Path within `association` to upload each local file to, keyed by local path. A file not in the mapping is uploaded to the root under its own name.
- **batch_size** (`int`): Maximum number of files per upload transaction.
- **device_id** (`Optional[str]`): ID of the device that produced the files, which must be in the organization the files are uploaded to. `None` records the calling device when a device makes the request, and no device otherwise.
- **caller_org_id** (`Optional[str]`): Organization to act in. Required when the caller belongs to more than one organization; otherwise the caller's only organization.
- **on_progress** (`Optional[roboto.storage.object_store.OnProgress]`): Function called with the number of bytes uploaded since its previous call. `None` reports no progress.

**Returns**

- `dict[pathlib.Path, str]`: ID of the file each local path was uploaded as, keyed by local path.

**Raises**

- `ValueError`: Two local files would be uploaded to the same path, which includes two files of the same name from different directories that `destination_paths` does not map. Raised before any upload starts.
- `OSError`: A local file does not exist or cannot be accessed. Raised before any upload starts.
- `ExceptionGroup`: One or more files in a batch failed to upload. It holds one exception per failed file. Roboto does not complete that batch's transaction, earlier batches stay uploaded, and later batches do not start.

### logger

```python
roboto.storage.file_service.logger
```

`from roboto.storage.file_service import logger`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/storage/file_service.py#L31-L31)
