swan.getSavedFileInfo
解释:获取本地文件的文件信息。此接口只能用于获取已保存到本地的文件,若需要获取临时文件信息,请使用 getFileInfo 接口。
方法参数
Object object
object参数说明
success返回参数说明
示例
在开发者工具中预览效果
扫码体验
请使用百度APP扫码
图片示例
代码示例
-
Page({ data: { filePath: '' }, saveFile() { this.toast('正在保存', 'loading'); swan.downloadFile({ url: 'https://smartprogram.baidu.com/docs/img/file-simple.pdf', success: res => { swan.saveFile({ tempFilePath: res.tempFilePath, success: res => { this.toast('保存成功', 'none'); this.setData('filePath', res.savedFilePath); }, fail: err => { this.toast('保存失败,请稍后重试', 'none'); } }); }, fail: err => { this.toast('下载失败,请稍后重试', 'none'); } }); }, getSavedFileInfo() { swan.getSavedFileList({ success: res => { if (res.fileList.length > 0) { const filePath = res.fileList[0].filePath; swan.getSavedFileInfo({ filePath, success: res => { swan.showModal({ title: 'success', content: JSON.stringify(res) }); console.log('getSavedFileInfo success', res); }, fail: err => { swan.showToast({ title: 'fail', icon: 'none' }); console.log('getSavedFileInfo fail', err); } }); } } }) }, toast(title, icon) { swan.showToast({title, icon}); }});
