轻源码

  • QingYuanMa.com
  • 全球最大的互联网技术和资源下载平台
搜索
一起源码网 门户 初级进阶 查看主题

微信小程序1028版本新增:文件管理 API说明

发布者: syhsieh | 发布时间: 2017-12-30 14:48| 查看数: 4512| 评论数: 1|帖子模式

wx.saveFile(OBJECT)

保存文件到本地。

OBJECT参数说明:

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

示例代码:

wx.startRecord({
  success: function(res) {
    var tempFilePath = res.tempFilePath
    wx.saveFile({
      tempFilePath: tempFilePath,
      success: function(res) {
        var savedFilePath = res.savedFilePath
      }
    })
  }
})

wx.getSavedFileList(OBJECT)

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

OBJECT参数说明:

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

success返回参数说明:

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

fileList中的项目说明:

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

示例代码:

wx.getSavedFileList({
  success: function(res) {
    console.log(res.fileList)
  }
})

wx.getSavedFileInfo(OBJECT)

获取本地文件的文件信息

OBJECT参数说明:

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

success返回参数说明:

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

示例代码:

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

wx.removeSavedFile(OBJECT)

删除本地存储的文件

OBJECT参数说明:

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

示例代码:

wx.getSavedFileList({
  success: function(res) {
    if (res.fileList.length > 0){
      wx.removeSavedFile({
        filePath: res.fileList[0].filePath,
        complete: function(res) {
          console.log(res)
        }
      })
    }
  }
})

wx.openDocument(OBJECT)

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

OBJECT参数说明:

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

示例代码

wx.downloadFile({
  url: ',
  success: function (res) {
    var filePath = res.tempFilePath 
    wx.openDocument({
      filePath: filePath,
      success: function (res) {
        console.log('打开文档成功')
      }
    })
  }
})

最新评论

2366593584 发表于 2022-5-7 09:04
源代码无删减版

浏览过的版块

轻源码让程序更轻更快

QingYuanMa.com

工作时间 周一至周六 8:00-17:30

侵权处理

客服QQ点击咨询

关注抖音号

定期抽VIP

Copyright © 2016-2021 https://www.171739.xyz/ 滇ICP备13200218号

快速回复 返回顶部 返回列表