swan.getFileInfo
解释:获取文件信息
方法参数
Object object
object参数说明
success返回参数说明
示例
扫码体验
请使用百度APP扫码
图片示例
代码示例 1 :
获取临时文件信息 在开发者工具中预览效果
Page({ data: { }, getFileInfo() { swan.downloadFile({ header: { 'Cache-Control': 'no-cache' }, url: 'https://smartprogram.baidu.com/docs/img/file-simple.pdf', success: res => { swan.getFileInfo({ filePath: res.tempFilePath, success: res => { console.log('getFileInfo success', res); swan.showModal({ title: 'getFileInfo success', content: JSON.stringify(res) }); }, fail: err => { console.log('getFileInfo fail', err); swan.showModal({ title: 'getFileInfo fail', content: JSON.stringify(err) }); } }); } }) } })
图片示例
代码示例 2 :
获取本地文件信息 在开发者工具中预览效果
Page({ data: { }, getFileInfo() { swan.chooseImage({ count: 1, success: res => { const tempFilePaths = res.tempFilePaths; // 本地文件的路径(也可通过swan.saveFile获取) swan.getFileInfo({ filePath: tempFilePaths[0], success: res => { swan.showModal({ title: 'getFileInfo success', content: JSON.stringify(res) }); console.log('getFileInfo success', res); }, fail: err => { swan.showModal({ title: 'getFileInfo fail', content: JSON.stringify(err) }); console.log('getFileInfo fail', err); } }) } }); } })
代码示例 3 - digestAlgorithm为sha1 :
获取本地文件信息 在开发者工具中预览效果
Page({ data: { }, getFileInfo() { swan.downloadFile({ header: { 'Cache-Control': 'no-cache' }, url: 'https://smartprogram.baidu.com/docs/img/file-simple.pdf', success: res => { swan.getFileInfo({ filePath: res.tempFilePath, digestAlgorithm: 'sha1', success: res => { console.log('getFileInfo success', res); swan.showModal({ title: 'getFileInfo success', content: JSON.stringify(res) }); }, fail: err => { console.log('getFileInfo fail', err); swan.showModal({ title: 'getFileInfo fail', content: JSON.stringify(err) }); } }); } }) } })
