# File Sharing

KayakNet supports sharing files through the chat system and marketplace.

## Current Capabilities

### Images in Chat

Share images directly in chat:

1. Click the image icon in chat
2. Select file from device
3. Image is encrypted and sent
4. Recipient sees inline preview

**Supported formats:**

* JPEG/JPG
* PNG
* GIF
* WebP

**Size limit:** 5MB per image

### Marketplace Images

Listings can include product images:

* Main image (required)
* Up to 5 additional images
* Compressed for network efficiency

## How It Works

### Image Encoding

```
1. User selects image
   │
2. Image resized (max 1920x1080)
   │
3. Compressed to JPEG (quality 85%)
   │
4. Base64 encoded
   │
5. Encrypted with room/recipient key
   │
6. Sent via standard message
```

### Delivery

* Small images (<100KB): Inline in message
* Large images: Chunked delivery
* DHT: Store-and-forward for offline

## Planned Features

### Full File Sharing (Coming Soon)

Share any file type:

* Documents (PDF, TXT, etc.)
* Archives (ZIP, TAR)
* Media (video, audio)
* Any binary file

### Distributed Storage

Large files will be:

1. Split into chunks
2. Encrypted per-chunk
3. Distributed across DHT
4. Retrieved on demand

### BitTorrent Integration

For large files:

* Create KayakNet torrents
* Share magnet links in chat
* Download via P2P within network

## Security

### Encryption

All files are encrypted:

* Room files: Room symmetric key
* DM files: Recipient's public key
* Marketplace: Public (for listings)

### Metadata

File metadata is also protected:

* Filename (optional to share)
* Size (padded)
* Type (not leaked)

## Best Practices

1. **Don't share sensitive files** - Unless absolutely necessary
2. **Verify recipients** - Ensure intended audience
3. **Delete after use** - Clear from local storage
4. **Check file sizes** - Large files may be slow

## Limitations

### Current Limitations

| Limitation             | Value       |
| ---------------------- | ----------- |
| Max image size         | 5MB         |
| Max images per listing | 6           |
| File types             | Images only |

### Network Constraints

* Large files strain onion routing
* Slow on mobile connections
* DHT storage is temporary

## API

### Upload Image (Chat)

```
POST /api/chat/upload
Content-Type: multipart/form-data

file: <image data>
room: #general
```

### Get Image

```
GET /api/chat/file?id=file_abc123
```

### Marketplace Image

```
POST /api/market/create
{
  "images": ["data:image/jpeg;base64,..."]
}
```
