---
title: "Upload files"
description: "Upload one or several files of any type and follow their progress."
canonical_url: "https://docs.flashdrive.space/sdk/upload-files"
---
# Upload files

> Upload one or several files of any type and follow their progress.

These examples use the latest stable release of the Python SDK.

[Set up the SDK](https://docs.flashdrive.space/sdk/installation) with an API key that has **Read / Write** permission. You can upload files of any type: documents, code, photos, video, audio, archives, data files and models. Each file can be up to 10,000,000,000 bytes, empty files included, and must fit in your workspace's available storage. See [limits](https://docs.flashdrive.space/reference/limits).

PDF, DOCX and UTF-8 text files, including Markdown, code, CSV and JSON, have their text read, so you can [read them by line and grep them](https://docs.flashdrive.space/sdk/files). Every other file is stored exactly as it is, with format `file`; read it by bytes, stream it or download it.

The SDK refuses `.git`, `.env` and system-leftover paths before sending anything.

## Upload a file

```python
from flashdrive import Flashdrive

with Flashdrive(drive_id="DRIVE_UUID") as client:
    batch = client.upload("handbook.pdf", folder_id="FOLDER_UUID")
    for receipt in batch.files:
        print(receipt.upload_id, receipt.document_id, receipt.status)
```

Replace `DRIVE_UUID` with an ID from `client.drives.list()`, and `FOLDER_UUID` with a folder ID, or leave `folder_id` out to upload to the top of the drive. The return value is an `UploadBatch`, even for one file. Each entry in `batch.files` is an `UploadReceipt` with `upload_id`, `drive_id`, `workspace_id`, `filename`, `external_id`, `document_id`, `operation_id` and `status`. By default the call returns once the service has finished processing every file.

The `document_id` is the file's ID in the drive: use it with `client.files` and `client.documents`.

## Upload several files

Inside the same client context:

```python
batch = client.upload(
    ["handbook.pdf", "policies.md", "intro.mp4"],
    concurrency=10,
    timeout=900,
    processing_timeout=1800,
    idempotency_key="handbook-upload-1",
)
```

Pass individual file paths; `upload()` does not read directories, so list a directory's files in your code first. One call takes up to 100,000 files. The SDK sends several files at once and groups the setup, completion and status requests of a multi-file upload into bulk requests of up to 1,000 files each. Files waiting for upload capacity on the drive continue automatically as capacity frees up.

### Large text batches

By default (`route="auto"`), a batch of at least 1,000 files or 1 GB, all of them text files, goes through a [bulk import](https://docs.flashdrive.space/sdk/bulk-imports), when imports are available, instead of one upload per file. Read its progress from `batch.import_status`; `batch.files` is empty. Pass `journal="PATH"` to make that import resumable: call `upload()` again with the same files and options to continue. `route="uploads"` always uploads file by file and gives a receipt for each file; `route="imports"` always imports.

To upload a local folder tree into matching drive folders, see [import a large collection](https://docs.flashdrive.space/sdk/bulk-imports).

## Give a file a stable identity

Every file has an `external_id`, its key within the drive. Without one, each upload creates a new file. Pass `external_id` on a single-file upload to choose the key yourself, so that your application can recognize the file later:

```python
client.upload("price-list.xlsx", external_id="price-list")
```

`external_id` works only when you upload one file per call, and it must be new to the drive. An upload with an `external_id` that the drive already has is refused with code `precondition_required`, and nothing is written. The call raises an `UploadBatchError` whose `failures` hold that error. To put new contents in an existing file, use [`documents.replace_file()`](https://docs.flashdrive.space/sdk/replace-and-label), which checks that nobody changed the file since you read it.

## Attach metadata

Pass `metadata` to label every file in the call:

```python
client.upload("q3-report.pdf", metadata={"team": "finance", "quarter": 3})
```

Metadata is a flat object whose values are strings, numbers, booleans or null:

- PDF, DOCX, TXT and Markdown files take up to 64 fields and 8,000 bytes.
- Files stored with format `file` take up to 40 fields and 6,000 bytes. They can also have a `title` (up to 500 bytes) and `tags`, a list of up to 32 strings of up to 64 bytes each, without commas or line breaks. Keys starting with `media.` are set by the service.

Read metadata back from `client.documents.get(document_id).metadata`. Metadata outside these limits is refused with code `invalid_metadata`.

## Return before processing finishes

```python
from flashdrive import Flashdrive

with Flashdrive(drive_id="DRIVE_UUID") as client:
    batch = client.upload(
        "recording.wav",
        idempotency_key="recording-1",
        wait=False,
    )
    receipt = batch.files[0]
    # Save these IDs if another process will resume the wait.
    print(receipt.upload_id, receipt.drive_id)
    ready = client.uploads.resume(receipt.upload_id, drive_id=receipt.drive_id)
    print(ready.status, ready.document_id)
```

`wait=False` returns once the service has verified the bytes and queued the file for processing. Call `uploads.resume()` when you are ready to wait. Save the idempotency key and receipts for [recovery](https://docs.flashdrive.space/sdk/upload-recovery).

## Check a file's text

A PDF or DOCX with no selectable text, such as a scan, is kept rather than failed. `client.documents.get(document_id)` returns a `Document` whose `text_status` is `none` with `text_status_reason` `no_text_layer`. A file stored with format `file` shows `none` with `not_text_format`. Uploading the file again does not change this.

## Choose concurrency and deadlines

<table>
<thead>
  <tr>
    <th>
      Option
    </th>
    
    <th>
      Behavior
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        concurrency
      </code>
    </td>
    
    <td>
      Integer from 1 through 50, default 3. How many files this call transfers at once.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        timeout
      </code>
    </td>
    
    <td>
      Seconds allowed to prepare and send all files, including waiting for capacity and retrying transfers. Default 600.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        processing_timeout
      </code>
    </td>
    
    <td>
      Seconds allowed, after the transfers, for the whole batch to finish processing. Default 600.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        wait=False
      </code>
    </td>
    
    <td>
      Return once the files are queued for processing.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        idempotency_key
      </code>
    </td>
    
    <td>
      A key of 1 to 128 visible ASCII characters that identifies this upload, so a retry does not upload twice.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        drive_id
      </code>
    </td>
    
    <td>
      The drive to upload to, overriding the client's drive and the workspace default.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        route
      </code>
    </td>
    
    <td>
      <code>
        "auto"
      </code>
      
       (default), <code>
        "uploads"
      </code>
      
       or <code>
        "imports"
      </code>
      
      . See <a href="#large-text-batches">
        large text batches
      </a>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        journal
      </code>
    </td>
    
    <td>
      A local file path that makes an import resumable.
    </td>
  </tr>
</tbody>
</table>

With the defaults, a call can take about 10 minutes for transfers plus 10 minutes for processing. Set both limits when your application needs a predictable total wait. Files the service has already accepted keep processing after a local timeout.

Processing does not use a transfer slot, so one slow file does not hold up the others. Concurrent upload calls share the drive's upload capacity. See the [async example](https://docs.flashdrive.space/sdk/async) and [errors and retries](https://docs.flashdrive.space/sdk/errors-and-retries).


## Sitemap

See the full [sitemap](https://docs.flashdrive.space/sitemap.md) for all pages.
