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

# Upload File

> Upload a file to a room's storage.

Upload a file to the room's R2 object storage.

## Endpoint

```
POST /v1/accounts/:accountId/upload
```

## Authentication

**Bearer token** required.

## Request Body

`multipart/form-data` with the following fields:

<ParamField body="roomId" type="string" required>
  The room to associate the file with.
</ParamField>

<ParamField body="userId" type="string" required>
  The user uploading the file.
</ParamField>

<ParamField body="file" type="File" required>
  The file to upload.
</ParamField>

## Response

<ResponseField name="file" type="UploadResult">
  The uploaded file's key and URL. See [`UploadResult`](/types/storage#uploadresult).
</ResponseField>

## Example

<CodeGroup>
  ```bash curl theme={null}
  curl -X POST https://api.collab-kit.com/v1/accounts/${ACCOUNT_ID}/upload \
    -H "Authorization: Bearer ${TOKEN}" \
    -F "roomId=c3003c93-60cf-4184-b85f-20be14d26dac" \
    -F "userId=user-001" \
    -F "file=@./screenshot.png"
  ```

  ```typescript JavaScript theme={null}
  const formData = new FormData();
  formData.append('roomId', roomId);
  formData.append('userId', userId);
  formData.append('file', fileInput.files[0]);

  const res = await fetch(`https://api.collab-kit.com/v1/accounts/${accountId}/upload`, {
    method: 'POST',
    headers: { 'Authorization': `Bearer ${token}` },
    body: formData,
  });
  const { data } = await res.json();
  console.log(data.file.url);
  ```
</CodeGroup>

```json Response theme={null}
{
  "type": "response",
  "success": true,
  "description": "File uploaded",
  "data": {
    "file": {
      "key": "c3003c93/uploads/screenshot.png",
      "url": "https://api.collab-kit.com/v1/accounts/${ACCOUNT_ID}/storage/c3003c93/uploads/screenshot.png"
    }
  },
  "error": null
}
```
