title: Taro.chooseMessageFile(option)
sidebar_label: chooseMessageFile
Selects a file from a client session.
Reference
Type
(option: Option) => Promise<SuccessCallbackResult>
Parameters
Option
Property |
Type |
Required |
Description |
count |
number |
Yes |
The maximum number of files that can be selected. 0-100 is allowed |
extension |
string[] |
No |
Filtered 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" |
No |
The selected file type |
complete |
(res: any) => void |
No |
The callback function used when the API call completed (always executed whether the call succeeds or fails) |
fail |
(res: any) => void |
No |
The callback function for a failed API call |
success |
(res: Result) => void |
No |
The callback function for a successful API call |
SuccessCallbackResult
Property |
Type |
Description |
tempFiles |
ChooseFile[] |
Returns an array of local temporary file objects for the selected files |
errMsg |
string |
Call result |
ChooseFile
res.tempFiles is composed as follows
Property |
Type |
Description |
name |
string |
The selected file name |
path |
string |
The path to the local temporary file |
size |
number |
The size of a local temporary file, in bytes |
time |
number |
Time 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
Property |
Description |
all |
All the files can be selected. |
video |
Only video files can be selected. |
image |
Only image files can be selected. |
file |
Files except images and videos can be selected. |
selectedType
Property |
Description |
video |
A video file is selected. |
image |
An image file is selected. |
file |
A 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
API |
WeChat Mini-Program |
H5 |
React Native |
Taro.chooseMessageFile |
✔️ |
|
|