WeChat applet API file



wx.saveFile(OBJECT)

Save the file locally.

OBJECT parameter description:

QQ截图20170208111050.png

Sample code:

wx.startRecord({
  success: function(res) {
    var tempFilePath = res.tempFilePath
    wx.saveFile({
      tempFilePath: tempFilePath,
      success: function(res) {
        var savedFilePath = res.savedFilePath
      }
    })
  }
})

bug & tip

  1. tip: The size limit of local file storage is 10M

wx.getSavedFileList(OBJECT)

Get the local saved file list

OBJECT parameter description:

QQ截图20170208111110.png

success Return parameter description:

QQ截图20170208111218.png

in fileList Project description:

QQ截图20170208111223.png

## Sample code:
wx.getSavedFileList({
  success: function(res) {
    console.log(res.fileList)
  }
})


wx.getSavedFileInfo(OBJECT)


Get the file information of the local file

OBJECT parameter description:

QQ截图20170208111227.png

success Return parameter description:

QQ截图20170208111239.png

##Sample code:

wx.getSavedFileInfo({
  filePath: 'wxfile://somefile', //仅做示例用,非真正的文件路径
  success: function(res) {
    console.log(res.size)
    console.log(res.createTime)
  }
})


wx.removeSavedFile(OBJECT)


Delete locally stored files

OBJECT parameter description:

QQ截图20170208111244.png##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 in a new page, supported formats: doc, xls, ppt, pdf, docx, xlsx, pptx


OBJECT parameter description:

ParametersDescriptionfilePathStringFunction##failFunctionNoCallback function for failed interface callcompleteFunctionNoEnd of interface call The callback function (executed successfully or failed)
wx.downloadFile({
  url: 'http://example.com/somefile.pdf',
  success: function (res) {
    var filePath = res.tempFilePath 
    wx.openDocument({
      filePath: filePath,
      success: function (res) {
        console.log('打开文档成功')
      }
    })
  }
})
RequiredDescription
is the file path, which can be obtained through downFile success
NoCallback function for successful interface call
Sample code