文件
wx.saveFile(object)
保存文件到本地
wx.chooseImage({
success: function(res) {
var tempFilePaths = res.tempFilePaths
wx.saveFile({
tempFilePath: tempFilePaths[0],//需要保存的文件的临时路径
success: function(res) {//返回文件的保存路径
var savedFilePath = res.savedFilePath//文件的保存路径
},
fail/complete: function (res) {//接口调用失败/结束的回调函数
}
})
}
})
注意:本地文件存储的大小限制为 10M
wx.getFileInfo(object)
获取本地已保存的文件列表
wx.getSavedFileList({
success: function(res) {
res.errMsg//接口调用结果
res.fileList//文件列表
res.fileList.filePath//文件的本地路径
res.fileList.createTime//文件的保存时的时间戳,从1970/01/01 08:00:00 到当前时间的秒数
res.fileList.size//文件大小,单位B
},
complete: function (res){//接口调用结束的回调函数(调用成功、失败都会执行)
}
})
wx.getSavedFileList(object)
获取本地文件的文件信息。此接口只能用于获取已保存到本地的文件,若需要获取临时文件信息,请使用 wx.getFileInfo 接口
wx.getSavedFileInfo({
filePath: 'wxfile://somefile', //文件路径
success: function(res) {
res.errMsg//接口调用结果
res.createTime//文件的保存时的时间戳,从1970/01/01 08:00:00 到当前时间的秒数
res.size//文件大小,单位B
}
complete: function (res){//接口调用结束的回调函数(调用成功、失败都会执行)
}
})
wx.getSavedFileInfo(object)
获取本地文件的文件信息。此接口只能用于获取已保存到本地的文件,若需要获取临时文件信息,请使用 wx.getFileInfo 接口
wx.getSavedFileInfo({
filePath: 'wxfile://somefile', //仅做示例用,非真正的文件路径
success: function(res) {
res.errMsg//接口调用结果
res.createTime//文件的保存时的时间戳,从1970/01/01 08:00:00 到当前时间的秒数
res.size//文件大小,单位B
}
complete: function (res){//接口调用结束的回调函数(调用成功、失败都会执行)
}
})
wx.removeSavedFile(object)
删除本地存储的文件
wx.getSavedFileList({
success: function(res) {
if (res.fileList.length > 0){
//删除本地存储的文件
wx.removeSavedFile({
filePath: res.fileList[0].filePath,//需要删除的文件路径
success/fail/complete: function (res) {//接口调用成功/失败/结束的回调函数
}
})
}
}
})
wx.openDocument(object)
新开页面打开文档,支持格式:doc, xls, ppt, pdf, docx, xlsx, pptx
wx.downloadFile({
url: 'http://example.com/somefile.pdf',
success: function (res) {
var filePath = res.tempFilePath
wx.openDocument({
filePath: filePath,//(必要)文件路径,可通过 downFile 获得
fileType://文件类型,指定文件类型打开文件,有效值 doc, xls, ppt, pdf, docx, xlsx, pptx
success/fail/complete: function (res) {//接口调用成功/失败/结束的回调函数
}
})
}
})