tt.getFileInfo
基础库 1.15.0 开始支持本方法,低版本需做 兼容处理。
获取文件信息。
语法
tt.getFileInfo(options)
参数说明
options
options 为 object 类型,属性如下:
属性名 | 类型 | 默认值 | 必填 | 说明 | 最低支持版本 |
---|---|---|---|---|---|
filePath | string | 是 | 要读取的文件路径 | 1.15.0 | |
success | Function | 否 | 接口调用成功的回调函数 | 1.15.0 | |
fail | Function | 否 | 接口调用失败的回调函数 | 1.15.0 | |
complete | Function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) | 1.15.0 |
回调成功
object 类型,属性如下:
属性 | 类型 | 说明 | 最低支持版本 |
---|---|---|---|
size | number | 文件大小,以字节为单位 | 1.15.0 |
回调失败
object 类型,属性如下:
属性 | 类型 | 说明 | 最低支持版本 |
---|---|---|---|
errMsg | string | "getFileInfo:fail " + 错误信息 | 1.15.0 |
效果示例

扫码体验
请使用字节宿主APP扫码
代码示例
const fileSystemManager = tt.getFileSystemManager();
tt.downloadFile({
url: "https://s3.pstatp.com/toutiao/resource/developer/static/img/main-logo.8e3a839.png",
success(res) {
// 获取下载的文件信息
getFileInfo(res.tempFilePath);
},
fail(res) {
console.log("下载失败", res.errMsg);
},
});
function getFileInfo(filePath) {
tt.getFileInfo({
filePath,
success(res) {
// 输出文件大小
console.log(res.size);
},
});
}
Bug & Tip
无
点击纠错
评价此篇文档