dom / latest / request / formdata.html /

Request.formData()

The formData() method of the Request interface reads the request body and returns it as a promise that resolves with a FormData object.

Syntax

formData()

Parameters

None.

Return value

A Promise that resolves with a FormData object.

Examples

const formData = new FormData();
const fileField = document.querySelector('input[type="file"]');

formData.append('username', 'abc123');
formData.append('avatar', fileField.files[0]);

const request = new Request('/myEndpoint', {
  method: 'POST',
  body: formData
});

request.formData().then(function(data) {
  // do something with the formdata sent in the request
});

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
formData
60
79
39
No
47
14.1
11.1
The method exists but always rejects with NotSupportedError. See bug 215671.
60
60
39
44
14.5
11.3
The method exists but always rejects with NotSupportedError. See bug 215671.
8.0

See also

© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Request/formData