# Uploads

## Upload File

`TOOL discourse_upload_file`

Upload an image or file to Discourse. Provide either: image_data (base64 with filename), a remote HTTP(S) URL, or an absolute local file path. user_id is required for avatar/background uploads. Returns upload_id for use in avatar/profile updates. Use short_url to embed images in posts.

Authentication: no security requirement declared for this operation.

Parameters:

- `upload_type` (argument, string, required) - Type of upload
  Type: string
  
  Type of upload
  
  enum: ["avatar","profile_background","card_background","composer"]

- `image_data` (argument, string, optional) - Base64 image data (with or without data URI prefix)
  Type: string
  
  Base64 image data (with or without data URI prefix)

- `url` (argument, string, optional) - Remote HTTP(S) URL for Discourse to fetch, or file:// URL / absolute local path
  Type: string
  
  Remote HTTP(S) URL for Discourse to fetch, or file:// URL / absolute local path

- `filename` (argument, string, optional) - Filename (required with image_data, optional for file paths)
  Type: string
  
  Filename (required with image_data, optional for file paths)

- `user_id` (argument, integer, optional) - User ID (required for avatar/profile_background/card_background uploads)
  Type: integer
  
  User ID (required for avatar/profile_background/card_background uploads)
  
  exclusiveMinimum: 0

## Examples

### JSON-RPC

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "discourse_upload_file",
    "arguments": {
        "upload_type": "avatar",
        "image_data": "string",
        "url": "string",
        "filename": "string",
        "user_id": 0
      }
  }
}
```

### TypeScript

```typescript
const result = await client.callTool({
  "name": "discourse_upload_file",
  "arguments": {
    "upload_type": "avatar",
    "image_data": "string",
    "url": "string",
    "filename": "string",
    "user_id": 0
  }
});
```

### Python

```python
result = await session.call_tool("discourse_upload_file", arguments={
  "upload_type": "avatar",
  "image_data": "string",
  "url": "string",
  "filename": "string",
  "user_id": 0
})
```
