Skip to content

feat: support multiple file uploads with the same field name#244

Closed
gumruyanzh wants to merge 1 commit intojetzig-framework:mainfrom
gumruyanzh:support-multiple-file-uploads
Closed

feat: support multiple file uploads with the same field name#244
gumruyanzh wants to merge 1 commit intojetzig-framework:mainfrom
gumruyanzh:support-multiple-file-uploads

Conversation

@gumruyanzh
Copy link

Summary

  • Adds request.files(name) to retrieve all files matching a field name from multipart form data
  • Handles <input type="file" multiple> where several files share the same field name

Problem

When an HTML form uses <input type="file" name="attachments" multiple>, the multipart request body contains multiple parts with the same field name but different filenames. The existing request.file("attachments") only returns the first match because MultipartQuery.getFile() returns on the first hit.

Changes

  • MultipartQuery.zig: Add getFiles() method that collects all files with a matching key
  • Request.zig: Add files() method as the public API wrapper

The existing request.file(name) is unchanged for backward compatibility.

Usage

// Single file (existing API, unchanged):
if (try request.file("upload")) |f| { ... }

// Multiple files (new API):
const uploaded = try request.files("attachments");
for (uploaded) |f| {
    // f.filename, f.content
}

Test plan

  • zig build succeeds
  • zig build test --summary all - all tests pass
  • Existing single-file upload tests continue to pass

Closes #182

🤖 Generated with Claude Code

Add `request.files(name)` to retrieve all files matching a field name
from multipart form data. This handles `<input type="file" multiple>`
where several files share the same field name in the request body.

The existing `request.file(name)` continues to return just the first
match for backward compatibility.

- Add `getFiles()` to MultipartQuery that collects all matching files
- Add `files()` to Request as the public API wrapper

Example usage:
  const uploaded = try request.files("attachments");
  for (uploaded) |f| {
      // f.filename, f.content
  }

Closes #182

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@gumruyanzh gumruyanzh closed this by deleting the head repository Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handle multiple file uploads

1 participant