课程表

微信小程序框架

微信小程序组件

微信小程序API

微信小程序开放接口

微信小程序工具

微信小程序设计规范

工具箱
速查手册

小程序API 文件

当前位置:免费教程 » 移动开发 » 微信小程序
2016年12月21日在wx.saveFile(OBJECT)基础上,新增了wx.getSavedFileList(OBJECT)wx.getSavedFileInfo(OBJECT)wx.removeSavedFile(OBJECT)
wx.openDocument(OBJECT)

wx.saveFile(OBJECT)

保存文件到本地。


OBJECT参数说明:

参数类型必填说明
tempFilePathString需要保存的文件的临时路径
successFunction返回文件的保存路径,res = {savedFilePath: '文件的保存路径'}
failFunction接口调用失败的回调函数
completeFunction接口调用结束的回调函数(调用成功、失败都会执行)

示例代码:

  1. wx.startRecord({
  2. success: function(res) {
  3. var tempFilePath = res.tempFilePath
  4. wx.saveFile({
  5. tempFilePath: tempFilePath,
  6. success: function(res) {
  7. var savedFilePath = res.savedFilePath
  8. }
  9. })
  10. }
  11. })

bug & tip

  1. tip: 本地文件存储的大小限制为 10M

wx.getSavedFileList(OBJECT)

获取本地已保存的文件列表

OBJECT参数说明:

参数类型必填说明
successFunction接口调用成功的回调函数,返回结果见success返回参数说明
failFunction接口调用失败的回调函数
completeFunction接口调用结束的回调函数(调用成功、失败都会执行)

success返回参数说明:

参数类型说明
errMsgString接口调用结果
fileListObject Array文件列表

fileList中的项目说明:

类型说明
filePathString文件的本地路径
createTimeNumber文件的保存时的时间戳,从1970/01/01 08:00:00 到当前时间的秒数
sizeNumber文件大小,单位B

示例代码:

  1. wx.getSavedFileList({
  2. success: function(res) {
  3. console.log(res.fileList)
  4. }
  5. })

wx.getSavedFileInfo(OBJECT)

获取本地文件的文件信息

OBJECT参数说明:

参数类型必填说明
filePathString文件路径
successFunction接口调用成功的回调函数,返回结果见success返回参数说明
failFunction接口调用失败的回调函数
completeFunction接口调用结束的回调函数(调用成功、失败都会执行)

success返回参数说明:

参数类型说明
errMsgString接口调用结果
sizeNumber文件大小,单位B
createTimeNumber文件的保存是的时间戳,从1970/01/01 08:00:00 到当前时间的秒数

示例代码:

  1. wx.getSavedFileInfo({
  2. filePath: 'wxfile://somefile', //仅做示例用,非真正的文件路径
  3. success: function(res) {
  4. console.log(res.size)
  5. console.log(res.createTime)
  6. }
  7. })

wx.removeSavedFile(OBJECT)

删除本地存储的文件

OBJECT参数说明:

参数类型必填说明
filePathString需要删除的文件路径
successFunction接口调用成功的回调函数
failFunction接口调用失败的回调函数
completeFunction接口调用结束的回调函数(调用成功、失败都会执行)

示例代码:

  1. wx.getSavedFileList({
  2. success: function(res) {
  3. if (res.fileList.length > 0){
  4. wx.removeSavedFile({
  5. filePath: res.fileList[0].filePath,
  6. complete: function(res) {
  7. console.log(res)
  8. }
  9. })
  10. }
  11. }
  12. })

wx.openDocument(OBJECT)

新开页面打开文档,支持格式:doc, xls, ppt, pdf, docx, xlsx, pptx

OBJECT参数说明:

参数说明必填说明
filePathString文件路径,可通过 downFile 获得
successFunction接口调用成功的回调函数
failFunction接口调用失败的回调函数
completeFunction接口调用结束的回调函数(调用成功、失败都会执行)

示例代码

  1. wx.downloadFile({
  2. url: 'http://example.com/somefile.pdf',
  3. success: function (res) {
  4. var filePath = res.tempFilePath
  5. wx.openDocument({
  6. filePath: filePath,
  7. success: function (res) {
  8. console.log('打开文档成功')
  9. }
  10. })
  11. }
  12. })
转载本站内容时,请务必注明来自W3xue,违者必究。
 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号