tencent cloud

FormData Overview
Last updated:2025-03-11 19:41:11
FormData Overview
Last updated: 2025-03-11 19:41:11
FormData is used to construct a request body of the form-data type.

Constructor

Create an object instance using new, as shown below:
new FormData(): FormData

Methodology

Methodology
Return Type
Description
append(key, value)
void
Add key-value pair data to form-data.
body()
ArrayBuffer
Return the form-data content, and further append operations are not allowed.
contentType()
string
Return the ContentType of form-data.

Samples

import http from 'pts/http';

const data = open('./sample/tmp.js');

export default function () {
// Construct a FormData instance using new.
const formData = new http.FormData();
formData.append('text', 'text');
formData.append('file', http.file(data, 'tmp.js'));
console.log(formData.contentType());
const resp = http.post('http://httpbin.org/post', formData.body(), {
headers: {'Content-Type': formData.contentType()}
});
console.log('formData: ', resp.body);
};

Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback