tencent cloud

All product documents
Tencent Cloud Observability Platform
http.file
Last updated: 2025-03-11 19:41:09
http.file
Last updated: 2025-03-11 19:41:09
http.file is used to construct the file object for upload in FormData.
file(data: string | ArrayBuffer, name?: string, contentType?: string): File

Parameters

Parameter
Type
Description
data
string or ArrayBuffer.
Text content.
name?
string
Optional; file name, defaults to timestamp in nanoseconds.
contentType?
string
Optional; content type, defaults to application/octet-stream.

Return

Type
Description
File
File object.

Samples

Construct a file object for upload in FormData:
import http from 'pts/http';

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

export default function () {
const file = http.file(data);
//@ts-ignore Ignore the verification.
console.log(file.data.length); // 231
console.log(file.name); // 1635403323707745000
console.log(file.contentType); // application/octet-stream
}
Construct a file object for upload in FormData, and pass in the name and contentType parameters:
import http from 'pts/http';

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

export default function () {
const file = http.file(data, 'data', 'application/json');
//@ts-ignore Ignore the verification.
console.log(file.data.length); // 231
console.log(file.name); // data
console.log(file.contentType); // application/json
}

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

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 available.

7x24 Phone Support