Skip to content

Add file upload handling middleware template #36

Description

@PAMulligan

Description

Add a file upload middleware template supporting multipart form data. This is one of the most commonly needed API features that isn't covered by the current templates.

Why

File uploads (avatars, documents, images) are required by the majority of production APIs. Providing a template with size limits, MIME type validation, and storage abstraction (local, S3, R2) means users don't have to figure this out from scratch.

Acceptance Criteria

  • Create a file upload middleware template for Hono
  • Support multipart/form-data parsing
  • Add configurable file size limits (default from `security.inputValidation.maxBodySizeKb`)
  • Add MIME type validation (allowlist pattern)
  • Create a storage abstraction interface with implementations for:
    • Local filesystem (development)
    • Cloudflare R2 (Workers deployments)
    • S3-compatible (Node.js deployments)
  • Add Zod schemas for upload validation
  • Include example route handler for single and multiple file uploads
  • Add integration tests for upload flows
  • CI passes

Implementation

```typescript
app.post('/upload', async (c) => {
const body = await c.req.parseBody();
const file = body['file'] as File;
// validate, store, respond
});
```

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions