# wx.chooseImage(Object object)

Selects an image from the local album or takes a photo with the camera.

# Parameters

# Object object

Attribute Type Default Required Description
count number 9 No The maximum number of images allowed
sizeType Array.<string> ['original', 'compressed'] No The size of the select image
sourceType Array.<string> ['album', 'camera'] No The source of the image
success function No The callback function for a successful API call
fail function No Callback function for failed API call
complete function No Callback function used when API call completed (always executed whether call succeeds or fails)

Valid values of object.sizeType

Value Description Minimum Version
original Original image
compressed Compressed image

Valid values of object.sourceType

Value Description Minimum Version
album Selects an image from the album
camera Takes a photo with the camera

# object.success callback function

# Parameters
# Object res
Property Type Description Minimum Version
tempFilePaths Array.<string> The list of local temporary file paths to images
tempFiles Array.<Object> The local temporary file list for images 1.2.0

res.tempFiles is composed as follows

Property Type Description
path string The path to the local temporary file
size number The size of a local temporary file, in bytes
wx.chooseImage({
  count: 1,
  sizeType: ['original', 'compressed'],
  sourceType: ['album', 'camera'],
  success (res) {
    // tempFilePath can be used as the src property of the img tag to display images.
    const tempFilePaths = res.tempFilePaths
  }
})
点击咨询小助手