> ## Documentation Index
> Fetch the complete documentation index at: https://docs-terra.withunify.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Google Drive Integration

> Upload files directly to Google Drive for permanent storage

# Google Drive Integration

> Files upload to Google Drive instead of Supabase Storage for permanent, shareable URLs.

## Why Drive?

* **Permanent URLs** — Never expire (unlike signed URLs)
* **Airtable compatible** — Attachments sync directly
* **Organized** — Folders per form and submission

## Architecture

```mermaid theme={null}
flowchart LR
    Upload[File Upload]
    API[API Route]
    Drive[(Google Drive)]

    Upload -->|stream| API
    API -->|service account| Drive
    Drive -->|file URL| API
    API -->|response| Upload
```

## Setup

### 1. Create Service Account

In Google Cloud Console:

1. Create a new project
2. Enable Google Drive API
3. Create a service account
4. Download JSON credentials

### 2. Configure Environment

```bash theme={null}
GOOGLE_SERVICE_ACCOUNT_JSON='{"type":"service_account",...}'
```

### 3. Share Folder

Share your Drive folder with the service account email.

### 4. Configure Form

In **Form Settings** → **Integrations**:

* Enter the Google Drive folder ID
* (Optional) Set per-field folder IDs

## File Structure

```
Drive Folder/
├── RENT-2024-001/
│   ├── id-front.jpg
│   └── tax-return.pdf
├── RENT-2024-002/
│   └── proof-of-income.pdf
```

## Upload Flow

Uploads are streamed directly to Google Drive via a resumable session. The API
validates the form, the file field, and (if provided) the per-field folder ID.

Required query params:

* `formId`
* `submissionId` (pending session ID)
* `filename`
* `questionId` (the files field ID)

Optional query params:

* `folderId` (per-field Drive folder override; must match the field config)

Headers:

* `Content-Type`
* `Content-Length`

Notes:

* Files inherit permissions from the parent folder (no public sharing).
* If a form requires auth, the upload endpoint enforces authentication.

***

<CardGroup cols={2}>
  <Card title="File Storage" icon="folder-open" href="/core-systems/data/file-storage">
    Supabase storage
  </Card>

  <Card title="Airtable" icon="table" href="/integrations/airtable">
    Sync with Drive URLs
  </Card>
</CardGroup>
