Dokumentation zur WeChat-Applet-Entwicklung
/ 微信小程序API 文件
微信小程序API 文件
wx.saveFile(OBJECT)
保存文件到本地。
OBJECT參數(shù)說明:
示例代碼:
wx.startRecord({ success: function(res) { var tempFilePath = res.tempFilePath wx.saveFile({ tempFilePath: tempFilePath, success: function(res) { var savedFilePath = res.savedFilePath } }) } })
bug & tip
tip
: 本地文件存儲的大小限制為 10M
wx.getSavedFileList(OBJECT)
獲取本地已保存的文件列表
OBJECT參數(shù)說明:
success返回參數(shù)說明:
fileList中的項目說明:
示例代碼:
wx.getSavedFileList({ success: function(res) { console.log(res.fileList) } })
wx.getSavedFileInfo(OBJECT)
獲取本地文件的文件信息
OBJECT參數(shù)說明:
success返回參數(shù)說明:
示例代碼:
wx.getSavedFileInfo({ filePath: 'wxfile://somefile', //僅做示例用,非真正的文件路徑 success: function(res) { console.log(res.size) console.log(res.createTime) } })
wx.removeSavedFile(OBJECT)
刪除本地存儲的文件
OBJECT參數(shù)說明:
示例代碼:
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參數(shù)說明:
參數(shù) | 說明 | 必填 | 說明 |
---|---|---|---|
filePath | String | 是 | 文件路徑,可通過 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)用成功、失敗都會執(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('打開文檔成功') } }) } })