wx.saveFile(OBJECT)保存文件到本地。OBJECT參數(shù)說(shuō)明:參數(shù)類型必填說(shuō)明tempFilePathString是需要保存的文件的臨時(shí)路徑successFunction否返回文件的保存路徑,res = {savedFilePath: '文件的保存路徑'}failFunction ...
保存文件到本地。
OBJECT參數(shù)說(shuō)明:
[tr]參數(shù)類型必填說(shuō)明[/tr]
| tempFilePath | String | 是 | 需要保存的文件的臨時(shí)路徑 |
| success | Function | 否 | 返回文件的保存路徑,res = {savedFilePath: '文件的保存路徑'} |
| fail | Function | 否 | 接口調(diào)用失敗的回調(diào)函數(shù) |
| complete | Function | 否 | 接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會(huì)執(zhí)行) |
示例代碼:
|
1
2
3
4
5
6
7
8
9
10
|
wx.startRecord({ success: function(res) { var tempFilePath = res.tempFilePath wx.saveFile({ tempFilePath: tempFilePath, success: function(res) { var savedFilePath = res.savedFilePath } }) }}) wx.getSavedFileList(OBJECT) |
獲取本地已保存的文件列表
OBJECT參數(shù)說(shuō)明:
[tr]參數(shù)類型必填說(shuō)明[/tr]
| success | Function | 否 | 接口調(diào)用成功的回調(diào)函數(shù),返回結(jié)果見(jiàn)success返回參數(shù)說(shuō)明 |
| fail | Function | 否 | 接口調(diào)用失敗的回調(diào)函數(shù) |
| complete | Function | 否 | 接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會(huì)執(zhí)行) |
success返回參數(shù)說(shuō)明:
[tr]參數(shù)類型說(shuō)明[/tr]
| errMsg | String | 接口調(diào)用結(jié)果 |
| fileList | Object Array | 文件列表 |
fileList中的項(xiàng)目說(shuō)明:
[tr]鍵類型說(shuō)明[/tr]
| filePath | String | 文件的本地路徑 |
| createTime | Number | 文件的保存時(shí)的時(shí)間戳,從1970/01/01 08:00:00 到當(dāng)前時(shí)間的秒數(shù) |
| size | Number | 文件大小,單位B |
示例代碼:
|
1
2
3
4
5
|
wx.getSavedFileList({ success: function(res) { console.log(res.fileList) }}) wx.getSavedFileInfo(OBJECT) |
復(fù)制代碼
獲取本地文件的文件信息
OBJECT參數(shù)說(shuō)明:
[tr]參數(shù)類型必填說(shuō)明[/tr]
| filePath | String | 是 | 文件路徑 |
| success | Function | 否 | 接口調(diào)用成功的回調(diào)函數(shù),返回結(jié)果見(jiàn)success返回參數(shù)說(shuō)明 |
| fail | Function | 否 | 接口調(diào)用失敗的回調(diào)函數(shù) |
| complete | Function | 否 | 接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會(huì)執(zhí)行) |
success返回參數(shù)說(shuō)明:
[tr]參數(shù)類型說(shuō)明[/tr]
| errMsg | String | 接口調(diào)用結(jié)果 |
| size | Number | 文件大小,單位B |
| createTime | Number | 文件的保存是的時(shí)間戳,從1970/01/01 08:00:00 到當(dāng)前時(shí)間的秒數(shù) |
示例代碼:
|
1
2
3
4
5
6
7
|
wx.getSavedFileInfo({ filePath: 'wxfile://somefile', //僅做示例用,非真正的文件路徑 success: function(res) { console.log(res.size) console.log(res.createTime) }}) wx.removeSavedFile(OBJECT) |
刪除本地存儲(chǔ)的文件
OBJECT參數(shù)說(shuō)明:
[tr]參數(shù)類型必填說(shuō)明[/tr]
| filePath | String | 是 | 需要?jiǎng)h除的文件路徑 |
| 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í)行) |
示例代碼:
|
1
2
3
4
5
6
7
8
9
10
11
12
|
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ō)明:
[tr]參數(shù)說(shuō)明必填說(shuō)明[/tr]
| 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í)行) |
示例代碼
|
1
2
3
4
5
6
7
8
9
10
11
12
|
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)文檔成功') } }) }}) |