Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

WeChat small program API file - delete local cache files


May 19, 2021 WeChat Mini Program Development Document


Table of contents


wx.openDocument(Object object)

Delete the local cache file. WeChat Client 7.0.12 displays the top right menu button by default before version 7.0.12, and later versions do not display by default, requiring active incoming showMenu.

Parameters

Object object

Property Type The default Required Description The lowest version
filePath string Is File path (local path), available through downloadFile
showMenu boolean false Whether Whether to display the menu in the upper right corner 2.11.0
fileType string Whether File type, specifying the file type to open the file 1.4.0
success function Whether The interface calls a successful callback function
fail function Whether The interface calls the failed callback function
complete function Whether Callback function at end of interface call (call succeeds, fails are executed)

The legal value of object.fileType

Value Description The lowest version
doc Doc format
docx Docx format
Xls xls format
xlsx xlsx format
Ppt ppt format
pptx pptx format
Pdf Pdf

The sample code


wx.downloadFile({
  // 示例 url,并非真实存在
  url: 'http://example.com/somefile.pdf',
  success: function (res) {
    const filePath = res.tempFilePath
    wx.openDocument({
      filePath: filePath,
      success: function (res) {
        console.log('打开文档成功')
      }
    })
  }
})