http.file 用于构造 FormData 中上传的文件对象。
file(data: string | ArrayBuffer, name?: string, contentType?: string): File
参数
参数 | 类型 | 描述 |
data | string 或 ArrayBuffer | 文件内容 |
name? | string | 可选,文件名,默认为纳秒级时间戳 |
contentType? | string | 可选,内容类型,默认为 application/octet-stream |
返回
类型 | 描述 |
文件对象 |
样例
构造用于 FormData 上传的文件对象:
import http from 'pts/http';const data = open('./sample/tmp.js');export default function () {const file = http.file(data);//@ts-ignore 忽略校验console.log(file.data.length); // 231console.log(file.name); // 1635403323707745000console.log(file.contentType); // application/octet-stream}
构造用于 FormData 上传的文件对象,并传入 name 和 contentType 参数:
import http from 'pts/http';const data = open('./sample/tmp.js');export default function () {const file = http.file(data, 'data', 'application/json');//@ts-ignore 忽略校验console.log(file.data.length); // 231console.log(file.name); // dataconsole.log(file.contentType); // application/json}