WeChat applet: File Management API description

Source: Internet
Author: User
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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.