文件
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
res.fileList.size
},
complete: function (res){
}
})
wx.getSavedFileList(object)
获取本地文件的文件信息。此接口只能用于获取已保存到本地的文件,若需要获取临时文件信息,请使用 wx.getFileInfo 接口
wx.getSavedFileInfo({
filePath: 'wxfile://somefile',
success: function(res) {
res.errMsg
res.createTime
res.size
}
complete: function (res){
}
})
wx.getSavedFileInfo(object)
获取本地文件的文件信息。此接口只能用于获取已保存到本地的文件,若需要获取临时文件信息,请使用 wx.getFileInfo 接口
wx.getSavedFileInfo({
filePath: 'wxfile://somefile',
success: function(res) {
res.errMsg
res.createTime
res.size
}
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,
fileType:
success/fail/complete: function (res) {
}
})
}
})
|