Skip to main content
Version: Next

Taro.chooseImage(option)

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

Reference

Type

(option: Option) => Promise<SuccessCallbackResult>

Parameters

Option

PropertyTypeRequiredDescription
countnumberNoThe maximum number of images allowed
sizeType("original" | "compressed")[]NoThe size of the select image
sourceType("album" | "camera" | "user" | "environment")[]NoThe source of the image
complete(res: any) => voidNoThe callback function used when the API call completed (always executed whether the call succeeds or fails)
fail(res: any) => voidNoThe callback function for a failed API call
success(res: Result) => voidNoThe callback function for a successful API call

sizeType

Valid values of object.sizeType

PropertyDescription
originalOriginal image
compressedcompressed

sourceType

Valid values of object.sourceType

PropertyDescription
albumSelects an image from the album
cameraTakes a photo with the camera
userUsing the front camera (Only H5)
environmentUsing the rear camera (Only H5)

SuccessCallbackResult

PropertyTypeDescription
tempFilePathsstring[]The list of local temporary file paths to images
tempFilesImageFile[]The local temporary file list for images
errMsgstringCall result

ImageFile

List of local temporary files for images

PropertyTypeRequiredDescription
pathstringYesThe path to the local temporary file
sizenumberYesThe size of a local temporary file, in bytes
typestringNoThe MIME type of the file.
(Only H5)
originalFileObjFileNoThe original browser File object.
(Only H5)

API Support

APIWeChat Mini-ProgramH5React Native
ImageFile.type✔️
ImageFile.originalFileObj✔️

Sample Code

Taro.chooseImage({
count: 1, // The default value is 9
sizeType: ['original', 'compressed'], // You can specify whether the image is original or compressed, both are available by default.
sourceType: ['album', 'camera'], // You can specify whether the source is an album or a camera, both are available by default.
success: function (res) {
// tempFilePath can be used as the src property of the img tag to display images.
var tempFilePaths = res.tempFilePaths
}
})

API Support

APIWeChat Mini-ProgramBaidu Smart-ProgramAlipay Mini-ProgramH5React Native
Taro.chooseImage✔️✔️✔️✔️✔️