# wx.addFileToFavorites(Object object)

Start from base library version 2.16.1. Please remaining backward compatible.

with Promise style call: Supported

Mini Program plugin: Not supported

Collection document

# parameter

# Object object

attribute type Default values Required Introductions
filePath string yes The file address to collect must be local or temporary
fileName string no Customize the filename, if left blank use the filePath file name
success function no Interface calls the successful callback function
fail function no Interface calls failed callback functions
complete function no Interface calls the end of the callback function (call success or failure will be executed)

# sample code


  // callback Writing method
  wx.downloadFile({
    url: URL, // Download url
    success (res) {
      // Download complete collection
      wx.addFileToFavorites({
        filePath: res.tempFilePath,
        success() {},
        fail: console.error,
      })
    },
    fail: console.error,
  })

  // async await Writing method
  const { tempFilePath } = await wx.downloadFile({
    url: URL, // Download url
  })
  // Download complete collection
  await wx.addFileToFavorites({
    filePath: res.tempFilePath,
  })