# Feature: Image Batch Upload

## Description
REST endpoint for uploading batches of UAV images for processing. Handles multipart form data with 10-50 images per request, validates sequence numbers, and queues images for async processing via F02.

## Component APIs Implemented
- `upload_image_batch(flight_id: str, batch: ImageBatch) -> BatchResponse`

## REST Endpoints
| Method | Endpoint | Description |
|--------|----------|-------------|
| POST | `/flights/{flightId}/images/batch` | Upload batch of 10-50 images |

## External Tools and Services
- **FastAPI**: Web framework for REST endpoints
- **python-multipart**: Multipart form data handling
- **Pydantic**: Validation

## Internal Methods
| Method | Purpose |
|--------|---------|
| `_validate_batch_size(images)` | Validate batch contains 10-50 images |
| `_validate_sequence_numbers(metadata)` | Validate start/end sequence are valid |
| `_validate_sequence_continuity(flight_id, start_seq)` | Validate sequence continues from last batch |
| `_parse_multipart_images(request)` | Parse multipart form data into image list |
| `_validate_image_format(image)` | Validate image file is valid JPEG/PNG |
| `_build_batch_response(result)` | Build response with accepted sequences |

## Unit Tests
1. **Batch size validation**
   - 20 images → accepted
   - 9 images → returns 400 (too few)
   - 51 images → returns 400 (too many)

2. **Sequence validation**
   - Valid sequence (start=100, end=119) → accepted
   - Invalid sequence (start > end) → returns 400
   - Gap in sequence → returns 400

3. **Flight validation**
   - Valid flight_id → accepted
   - Non-existent flight_id → returns 404

4. **Image validation**
   - Valid JPEG images → accepted
   - Corrupted image → returns 400
   - Non-image file → returns 400

5. **Size limits**
   - 50 × 2MB images → accepted
   - Batch > 500MB → returns 413

## Integration Tests
1. **Sequential batch uploads**
   - Upload batch 1 (seq 0-49) → success
   - Upload batch 2 (seq 50-99) → success
   - Verify next_expected increments correctly

2. **Large image handling**
   - Upload 50 × 8MB images → success within timeout
   - Verify all images queued for processing

3. **Rate limiting**
   - Rapid consecutive uploads → eventually returns 429
   - Wait and retry → succeeds

4. **Concurrent uploads to same flight**
   - Two clients upload different batches → both succeed
   - Verify sequence integrity maintained

