搜索
首页微信小程序小程序开发微信小程序:文件管理 API说明

微信小程序:文件管理 API说明

Mar 03, 2017 am 10:48 AM
微信小程序

wx.saveFile(OBJECT)

保存文件到本地。
OBJECT参数说明:
[tr]参数类型必填说明[/tr]

tempFilePath String 需要保存的文件的临时路径
success Function 返回文件的保存路径,res = {savedFilePath: '文件的保存路径'}
fail Function 接口调用失败的回调函数
complete Function 接口调用结束的回调函数(调用成功、失败都会执行)

示例代码:

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



获取本地已保存的文件列表
OBJECT参数说明:
[tr]参数类型必填说明[/tr]

success Function 接口调用成功的回调函数,返回结果见success返回参数说明
fail Function 接口调用失败的回调函数
complete Function 接口调用结束的回调函数(调用成功、失败都会执行)

success返回参数说明:
[tr]参数类型说明[/tr]

errMsg String 接口调用结果
fileList Object Array 文件列表

fileList中的项目说明:
[tr]键类型说明[/tr]

filePath String 文件的本地路径
createTime Number 文件的保存时的时间戳,从1970/01/01 08:00:00 到当前时间的秒数
size Number 文件大小,单位B

示例代码:

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

复制代码
获取本地文件的文件信息
OBJECT参数说明:
[tr]参数类型必填说明[/tr]

filePath String 文件路径
success Function 接口调用成功的回调函数,返回结果见success返回参数说明
fail Function 接口调用失败的回调函数
complete Function 接口调用结束的回调函数(调用成功、失败都会执行)

success返回参数说明:
[tr]参数类型说明[/tr]

errMsg String 接口调用结果
size Number 文件大小,单位B
createTime Number 文件的保存是的时间戳,从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参数说明:
[tr]参数类型必填说明[/tr]

filePath String 需要删除的文件路径
success Function 接口调用成功的回调函数
fail Function 接口调用失败的回调函数
complete Function 接口调用结束的回调函数(调用成功、失败都会执行)

示例代码:

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参数说明:
[tr]参数说明必填说明[/tr]

filePath String 文件路径,可通过 downFile 获得
success Function 接口调用成功的回调函数
fail Function 接口调用失败的回调函数
complete Function 接口调用结束的回调函数(调用成功、失败都会执行)

示例代码

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


更多微信小程序:文件管理 API说明相关文章请关注PHP中文网!

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

mPDF

mPDF

mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

VSCode Windows 64位 下载

VSCode Windows 64位 下载

微软推出的免费、功能强大的一款IDE编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

功能强大的PHP集成开发环境