New in minor program version 1028: File Management API description, wx. saveFile (OBJECT)
Save the file to your local device.
OBJECT parameter description:
[Tr] parameter type required description [/tr]
| TempFilePath |
String |
Yes |
Temporary path of the file to be saved |
| Success |
Function |
No |
Returned file storage path, res = {savedFilePath: 'File storage path '} |
| Fail |
Function |
No |
Callback function for interface call failure |
| Complete |
Function |
No |
The callback function after the interface call ends. (the callback function is executed if the call succeeds or fails) |
Sample code:
wx.startRecord({ success: function(res) { var tempFilePath = res.tempFilePath wx.saveFile({ tempFilePath: tempFilePath, success: function(res) { var savedFilePath = res.savedFilePath } }) }}) wx.getSavedFileList(OBJECT)
Obtain the list of saved local files
OBJECT parameter description:
[Tr] parameter type required description [/tr]
| Success |
Function |
No |
The callback function that successfully calls the API. for the returned results, see the success return parameter description. |
| Fail |
Function |
No |
Callback function for interface call failure |
| Complete |
Function |
No |
The callback function after the interface call ends. (the callback function is executed if the call succeeds or fails) |
Success return parameters:
[Tr] parameter type description [/tr]
| ErrMsg |
String |
Interface call result |
| FileList |
Object Array |
File list |
Project description in fileList:
[Tr] Key type description [/tr]
| FilePath |
String |
Local file path |
| CreateTime |
Number |
The timestamp when the file is saved, from 08:00:00 to the current time in seconds |
| Size |
Number |
File size, in B |
Sample code:
wx.getSavedFileList({ success: function(res) { console.log(res.fileList) }}) wx.getSavedFileInfo(OBJECT)
Copy code
Obtain the file information of a local file
OBJECT parameter description:
[Tr] parameter type required description [/tr]
| FilePath |
String |
Yes |
File path |
| Success |
Function |
No |
The callback function that successfully calls the API. for the returned results, see the success return parameter description. |
| Fail |
Function |
No |
Callback function for interface call failure |
| Complete |
Function |
No |
The callback function after the interface call ends. (the callback function is executed if the call succeeds or fails) |
Success return parameters:
[Tr] parameter type description [/tr]
| ErrMsg |
String |
Interface call result |
| Size |
Number |
File size, in B |
| CreateTime |
Number |
The time stamp for saving the file, from 08:00:00 to the current time in seconds |
Sample code:
Wx. getSavedFileInfo ({filePath: 'wxfile: // somefile', // for example only, non-real file path success: function (res) {console. log (res. size) console. log (res. createTime)}) wx. removeSavedFile (OBJECT)
Delete Locally stored files
OBJECT parameter description:
[Tr] parameter type required description [/tr]
| FilePath |
String |
Yes |
File path to be deleted |
| Success |
Function |
No |
Callback function for successful API call |
| Fail |
Function |
No |
Callback function for interface call failure |
| Complete |
Function |
No |
The callback function after the interface call ends. (the callback function is executed if the call succeeds or fails) |
Sample code:
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)
Open the document on the new page. the supported formats are doc, xls, ppt, pdf, docx, xlsx, and pptx.
OBJECT parameter description:
[Tr] parameter description required description [/tr]
| FilePath |
String |
Yes |
File path, which can be obtained through downFile |
| Success |
Function |
No |
Callback function for successful API call |
| Fail |
Function |
No |
Callback function for interface call failure |
| Complete |
Function |
No |
The callback function after the interface call ends. (the callback function is executed if the call succeeds or fails) |
Sample code
Wx. downloadFile ({url: 'http: // example.com/somefile.pdf', success: function (res) {var filePath = res. tempFilePath wx. openDocument ({filePath: filePath, success: function (res) {console. log ('document opened successfully ')}})}})
More small programs: File Management API instructions related articles please follow the PHP Chinese network!