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

WeChat small program API picture - Select files from client sessions


May 18, 2021 WeChat Mini Program Development Document


Table of contents


wx.chooseMessageFile(Object object)

The base library 2.5.0 starts to support, and the lower version needs to be compatible.

Select the file from the client session.

Parameters

Object object

Property Type The default Required Description The lowest version
count number Is You can select up to 0 to 100 files
type string 'all' Whether The type of file selected
extension Array.<string> Whether Filtered according to the file's expansion name, only type-file is valid. E ach item cannot be an empty string. It is not filtered by default. 2.6.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.type

Value Description The lowest version
all Select from all files
video Only video files can be selected
image Only picture files can be selected
file You can select files other than pictures and videos

object.success callback function

Parameters
Object res
Property Type Description
tempFiles Array.<Object> Returns an array of local temporary file objects for the selected file

The structure of res.tempFiles

Property Type Description
path string Local Temporary File Path (Local Path)
size number Local temporary file size, unit B
name string The name of the file selected
type string The type of file selected
time number Select the session time of the file, Unix timestamp, and the tool does not support this property for the time being

Type's legal value

value illustrate Minimum version
video Selected video files
image Selected a picture file
file Selected files except pictures and videos
wx.chooseMessageFile({
  count: 10,
  type: 'image',
  success (res) {
    // tempFilePath可以作为img标签的src属性显示图片
    const tempFilePaths = res.tempFiles
  }
})