title: Taro.chooseMedia(option)
sidebar_label: chooseMedia
Take or select a picture or video from user phone’s album.
Reference
Type
(option: Option) => Promise<SuccessCallbackResult>
Parameters
Option
| Property |
Type |
Required |
Description |
| count |
number |
No |
Maximum number of files that can be selected |
| mediaType |
("video" | "image")[] |
No |
Media type. |
| sourceType |
("album" | "camera")[] |
No |
Sources of images and videos. |
| maxDuration |
number |
No |
Maximum recording time in seconds for video recording. The range of time is between 3s and 30s. |
| sizeType |
("original" | "compressed")[] |
No |
Specifies whether to compress the selected file. (Only mediaType === "image") |
| camera |
string |
No |
Specifies whether to use the front or rear camera. (Only sourceType === "camera") |
| 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 |
ChooseMedia[] |
Returns an array of local temporary file objects for the selected files |
| type |
string |
media type. ("video" | "image") |
ChooseMedia
List of local temporary files
| Property |
Type |
Description |
| tempFilePath |
string |
Local temporary file path |
| size |
number |
The size of a local temporary file, in bytes |
| duration |
number |
Duration of the video |
| height |
number |
Height of the video |
| width |
number |
Width of the video |
| thumbTempFilePath |
string |
Temporary file path for video thumbnails |
mediaType
| Property |
Description |
| video |
Only take videos or select videos from albums. |
| image |
Only take pictures or select pictures from albums. |
sourceType
| Property |
Description |
| album |
Select from albums |
| camera |
Shooting with a camera |
camera
| Property |
Description |
| back |
Using the rear camera |
| front |
Using the front camera |
Sample Code
Taro.chooseMedia({ count: 9, mediaType: ['image','video'], sourceType: ['album', 'camera'], maxDuration: 30, camera: 'back', success: (res) => { console.log(res.tempFiles) console.log(res.type) }})
API Support
| API |
WeChat Mini-Program |
H5 |
React Native |
| Taro.chooseMedia |
✔️ |
|
✔️ |