FileSystemManager.stat
2020-08-26 16:18 更新
解释:获取文件 Stats 对象。
Web 态说明:受浏览器限制,Web 态不支持文件系统相关功能,调用该方法会执行失败回调函数。
方法参数:Object object
object
参数说明:
success 返回参数说明:
stats 返回值说明
示例
图片示例
代码示例
<view class="wrap">
<button type="primary" bindtap="stat">获取文件 Stats 对象</button>
</view>
Page({
data: {
filePath: ''
},
onLoad() {
this.fileSystemManager = swan.getFileSystemManager();
swan.downloadFile({
url: 'https://smartprogram.baidu.com/docs/img/logo.png',
success: res => {
swan.showToast({
title: `文件预下载完成,临时路径为${res.tempFilePath}`,
icon: 'none'
});
// 此为 “本地临时文件” 路径。
console.log(res.tempFilePath);
this.data.filePath = res.tempFilePath;
}
});
},
stat() {
this.fileSystemManager.stat({
path: this.data.filePath,
// path: `${swan.env.USER_DATA_PATH}/demo.txt`,// 本地文件路径
success: res => {
swan.showModal({
title: 'stat',
content: JSON.stringify(res)
});
console.log('stat success', res);
},
fail: err => {
swan.showToast({
title: JSON.stringify(err),
icon: 'none'
});
console.log('stat fail', err);
}
});
}
});
以上内容是否对您有帮助:
更多建议: