Skip to content

abhithesys/fileupload-poc

Repository files navigation

File Upload (POC)

This adds a minimal, in-memory file upload capability wired to the chat composer and a Next.js API route.

What was added

  • UI (src/components/Composer.tsx):
    • onUploadFile prop: (file: { id: string; file: File }) => Promise<unknown>
    • Hidden native file input + Attach button (design system) with paperclip icon
    • Upload state chips with statuses: UploadingUploaded
    • Cross button on each chip to remove files before sending
    • Send button disabled while any file is uploading
    • On submit, uploaded files are included in the message context and local upload state is cleared
  • API:
    • POST /api/files (src/app/api/files/route.ts) accepts multipart/form-data with one or more file fields and optional id
    • Files are stored in-memory as text (using File.text())
    • In-memory store: src/app/api/files/fileStore.ts with addFile, removeFile, getFile, listFiles
    • POST /api/chat (src/app/api/chat/route.ts) includes read_file tool in the system prompt

API details

  • Endpoint: POST /api/files
  • Body: multipart/form-data
    • file: one or more file parts
    • id (optional): client-generated ID to correlate UI with server state
  • Response: { files: Array<{ id, name, type, size }> }
  • Storage: in-memory, text-only; not persisted, cleared on server restart

Caveats

  • This approach is only suitable for text-based files like CSV, JSON, etc.
  • In-memory store is not suitable for production (no persistence, no limits)
  • Consider size limits, validation, and auth for real-world use

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published