FileSystemManager.getFileInfo
收藏我的收藏
基础库 1.15.0 开始支持本方法,这是一个异步方法。
获取 临时目录 (ttfile://tmep) 或 用户目录 (ttfile://user) 下的文件信息。
前提条件 | 无 |
业务背景 | 无 |
使用限制 | 无 |
注意事项 | 无 |
相关教程 | 无 |
语法
FileSystemManager.getFileInfo(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 |
errMsg | string | "FileSystemManager.getFileInfo:ok" | 1.15.0 |
回调失败
object 类型,属性如下:
属性名 | 类型 | 说明 | 最低支持版本 |
---|---|---|---|
errMsg | string | "FileSystemManager.getFileInfo:fail" + 详细错误信息 | 1.15.0 |
错误码
errNo | errMsg | 说明 | 最低支持版本 |
---|---|---|---|
21101 | permission denied, $apiName $filePath | 1.15.0 | |
21102 | no such file or directory, $apiName $filePath | 1.15.0 | |
21103 | operation not permitted, $apiName $filePath | 1.15.0 | |
10401 | Internal error:sandbox is nil | 小游戏框架内部错误,有需要请创建工单咨询 | 1.15.0 |
20000 | params $paramName is required | 1.15.0 | |
20000 | params $paramName type is not $paramType type | 1.15.0 | |
20000 | $paramName is invalid | 1.15.0 | |
20001 | invalid param | 参数错误 | 1.15.0 |
20000 | internal error | 小游戏框架内部错误,有需要请创建工单咨询 | 1.15.0 |
代码示例
const fileSystemManager = tt.getFileSystemManager(); tt.chooseImage({ success(res) { getFileInfo(res.tempFilePaths[0]); }, }); function getFileInfo(filePath) { fileSystemManager.getFileInfo({ filePath, success(res) { console.log("文件信息:", res); }, fail(res) { console.log("调用失败", res.errMsg); }, }); }