Skip to content

Conversation

@BlackAsLight
Copy link
Contributor

@BlackAsLight BlackAsLight commented Jan 2, 2026

This pull request introduces a new package (@std/formdata), offering a way to process FormData content in a streaming manner. It is based off the RFC 7578 spec.

When a website submits a standard HTML form, it is sent using the multipart/form-data content type. Currently, servers must wait until the entire payload has been received before any processing can begin, which often forces them to impose strict size limits and rely on client-side JavaScript to handle larger uploads. This pull request addresses that limitation by enabling servers to process large uploads incrementally, without requiring JavaScript on the client, and even allowing it to be completely disabled.

Note: The basic Error class was used when throwing an error. Suggestions on what ones they should be changed to are welcome.

Example

import { assertEquals } from "jsr:@std/assert";
import { FormDataDecoderStream } from "jsr:@std/formdata";

const request = new Request("https://example.com", {
  method: "POST",
  body: function() {
    const formData = new FormData();
    formData.append("a", "b");
    return formData;
  }()
});

for await (const entry of FormDataDecoderStream.from(request)) {
  assertEquals(entry.name, "a");
  assertEquals(await new Response(entry.value).text(), "b");
}

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.

1 participant