微信小程序開(kāi)發(fā)文檔
/ 微信小程序API 文件
微信小程序API 文件
wx.saveFile(OBJECT)
保存文件到本地。
OBJECT參數(shù)說(shuō)明:
示例代碼:
wx.startRecord({ success: function(res) { var tempFilePath = res.tempFilePath wx.saveFile({ tempFilePath: tempFilePath, success: function(res) { var savedFilePath = res.savedFilePath } }) } })
bug & tip
tip
: 本地文件存儲(chǔ)的大小限制為 10M
wx.getSavedFileList(OBJECT)
獲取本地已保存的文件列表
OBJECT參數(shù)說(shuō)明:
success返回參數(shù)說(shuō)明:
fileList中的項(xiàng)目說(shuō)明:
示例代碼:
wx.getSavedFileList({ success: function(res) { console.log(res.fileList) } })
wx.getSavedFileInfo(OBJECT)
獲取本地文件的文件信息
OBJECT參數(shù)說(shuō)明:
success返回參數(shù)說(shuō)明:
示例代碼:
wx.getSavedFileInfo({ filePath: 'wxfile://somefile', //僅做示例用,非真正的文件路徑 success: function(res) { console.log(res.size) console.log(res.createTime) } })
wx.removeSavedFile(OBJECT)
刪除本地存儲(chǔ)的文件
OBJECT參數(shù)說(shuō)明:
示例代碼:
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)
新開(kāi)頁(yè)面打開(kāi)文檔,支持格式:doc, xls, ppt, pdf, docx, xlsx, pptx
OBJECT參數(shù)說(shuō)明:
參數(shù) | 說(shuō)明 | 必填 | 說(shuō)明 |
---|---|---|---|
filePath | String | 是 | 文件路徑,可通過(guò) downFile 獲得 |
success | Function | 否 | 接口調(diào)用成功的回調(diào)函數(shù) |
fail | Function | 否 | 接口調(diào)用失敗的回調(diào)函數(shù) |
complete | Function | 否 | 接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會(huì)執(zhí)行) |
示例代碼
wx.downloadFile({ url: 'http://example.com/somefile.pdf', success: function (res) { var filePath = res.tempFilePath wx.openDocument({ filePath: filePath, success: function (res) { console.log('打開(kāi)文檔成功') } }) } })