tencent cloud

FormData.append
Last updated: 2025-03-11 19:41:11
FormData.append
Last updated: 2025-03-11 19:41:11
FormData.append is used to add key-value pair data to form-data data.
append(key: string, value: string | File): void

Parameters

Parameter
Type
Description
key
string
The key to add data.
value
string or File.
The value to add data, which can be of string or File type.

Return

Type
Description
void
No data returned.

Samples

import http from 'pts/http';

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

export default function () {
const formData = new http.FormData();
// Add data with value as string.
formData.append('text', 'text');
// Add data with value as File.
formData.append('file', http.file(data, 'tmp.js'));
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