wx.saveFile(OBJECT)


保存文件到本地。

OBJECT参数说明:

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

success返回参数说明:

参数说明
savedFilePath文件的保存路径

示例代码:

wx.chooseImage({  success: function(res) {    var tempFilePath = res.tempFilePath    wx.saveFile({      tempFilePath: tempFilePath[0],      success: function(res) {        var savedFilePath = res.savedFilePath      }    })  }})

bug & tip

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

  • wx.getFileInfo(OBJECT)

    基础库 1.4.0 开始支持,低版本需做兼容处理

    获取文件信息

    OBJECT参数说明:

    参数名类型必填说明
    filePathString是本地文件路径
    digestAlgorithmString否计算文件摘要的算法,默认值 md5,有效值:md5,sha1
    successFunction否接口调用成功的回调函数
    failFunction否接口调用失败的回调函数
    completeFunction否接口调用结束的回调函数(调用成功、失败都会执行)

    success返回参数说明:

    参数名类型说明
    sizeNumber文件大小,单位:B
    digestString按照传入的 digestAlgorithm 计算得出的的文件摘要
    errMsgString调用结果

    示例代码:

    wx.getFileInfo({    success(res) {        console.log(res.size)        console.log(res.digest)    }})

    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)

    获取本地文件的文件信息。此接口只能用于获取已保存到本地的文件,若需要获取临时文件信息,请使用 wx.getFileInfo 接口。

    OBJECT参数说明:

    参数类型必填说明
    filePathString是文件路径
    successFunction否接口调用成功的回调函数,返回结果见success返回参数说明
    微信小程序微信接收的文件

    http://www.xiaochengxub.com/read-99796.html

    声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。

    上一篇小程序码云调用实现方式
    下一篇小程序“搅局”电商企业如何决战下半场

    觉得文章有用就打赏一下吧

    微信扫一扫打赏