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");
}

@tomas-zijdemans
Copy link
Contributor

Sorry, I'm quite inexperienced in deno std.

Looking at YAML parsing in the std it uses SyntaxError for malformed input. So instead of:

if (buffer == undefined) throw new Error("Unexpected EOF");

you could do:

if (buffer == undefined) throw new SyntaxError("Unexpected EOF");

...and so on.

Then, when the caller makes a mistake you could opt for TypeError. So instead of:

if (contentType == undefined) {
    throw new Error("Content-Type header is missing");
}

you could do:

if (contentType == undefined) {
   throw new TypeError("Content-Type header is missing");
}

...and so on

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.

2 participants