Skip to main content
Version: 3.x

Taro.chooseMessageFile(option)

Selects a file from a client session.

Reference

Type

(option: Option) => Promise<SuccessCallbackResult>

Parameters

Option

PropertyTypeRequiredDescription
countnumberYesThe maximum number of files that can be selected. 0-100 is allowed
extensionstring[]NoFiltered by the file extension name. It takes effect only when type==file. The strings within it cannot be empty. Filtering is not performed by default.
type"all" | "video" | "image" | "file"NoThe selected file type
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

SuccessCallbackResult

PropertyTypeDescription
tempFilesChooseFile[]Returns an array of local temporary file objects for the selected files
errMsgstringCall result

ChooseFile

res.tempFiles is composed as follows

PropertyTypeDescription
namestringThe selected file name
pathstringThe path to the local temporary file
sizenumberThe size of a local temporary file, in bytes
timenumberTime when the session of the selected file is sent. It is a Unix timestamp and not supported in WeChat DevTools.
type"video" | "image" | "file"The selected file type

selectType

PropertyDescription
allAll the files can be selected.
videoOnly video files can be selected.
imageOnly image files can be selected.
fileFiles except images and videos can be selected.

selectedType

PropertyDescription
videoA video file is selected.
imageAn image file is selected.
fileA file except images and videos is selected.

Sample Code

Taro.chooseMessageFile({
count: 10,
type: 'image',
success: function (res) {
// tempFilePath can be used as the src property of the img tag to display images.
const tempFilePaths = res.tempFilePaths
}
})

API Support

APIWeChat Mini-ProgramH5React Native
Taro.chooseMessageFile✔️