Skip to main content

LensStudio:Network.FormData

Class

Holds key-value pairs and file attachments for encoding multipart HTTP request bodies.

Index

Methods

Example

// FormData builds multipart HTTP request bodies.
// Create an instance, then append string or binary parts with headers.
const { FormData, HttpRequest } = await import('LensStudio:Network');

const form = new FormData();

// Append a plain-text field
form.append('field=hello', { 'Content-Disposition': 'form-data; name="greeting"' });
console.log('Appended text part to FormData');

// Append a binary payload
const binaryData = new Uint8Array([0x89, 0x50, 0x4e, 0x47]);
form.append(binaryData, {
'Content-Disposition': 'form-data; name="file"; filename="image.png"',
'Content-Type': 'image/png'
});
console.log('Appended binary part to FormData');

// Use the FormData as the body of an HttpRequest
const request = new HttpRequest();
request.url = 'https://httpbin.org/post';
request.method = HttpRequest.Method.Post;
request.body = form;
console.log('Created HttpRequest with FormData body, method:', request.method);

Constructors

Constructor

new FormData(): FormData

Constructs a new FormData instance for building multipart HTTP request bodies.

Returns

FormData

Methods

append()

append(body, headers): void

Appends a body part with optional headers to the form data.

Parameters

ParameterType
bodystring | Uint8Array<ArrayBufferLike>
headersany

Returns

void