Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Microsoft Playwright FormData

From Leeroopedia
Revision as of 11:36, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Microsoft_Playwright_FormData.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Template:Implementation Page

Overview

MultipartFormData builds multipart/form-data request bodies for HTTP requests, supporting both text fields and file uploads with proper MIME type detection.

Description

The MultipartFormData class constructs RFC 2046 compliant multipart form data payloads. It generates a unique boundary string and provides methods to add text fields and file fields. File fields automatically detect MIME types using the mime library based on file extension. The class produces a properly formatted Buffer suitable for use as an HTTP request body.

Usage

Used internally when Playwright needs to submit form data with file uploads through the API request context.

Code Reference

Source Location

packages/playwright-core/src/server/formData.ts (92 lines)

Class Signature

export class MultipartFormData {
  constructor()
  contentTypeHeader(): string
  addField(name: string, value: string): void
  addFileField(name: string, value: { name: string; mimeType?: string; buffer: Buffer }): void
  finish(): Buffer
}

Import

import { MultipartFormData } from './server/formData';

I/O Contract

Inputs

  • Text fields: name-value string pairs
  • File fields: name, file name, optional MIME type, and file buffer

Outputs

  • contentTypeHeader() returns the Content-Type header including the boundary
  • finish() returns the complete multipart body as a Buffer

Usage Examples

Building Form Data

const form = new MultipartFormData();
form.addField('username', 'testuser');
form.addFileField('avatar', { name: 'photo.png', buffer: fileBuffer });
const body = form.finish();
const contentType = form.contentTypeHeader();

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment