title: Taro.chooseMedia(option)

sidebar_label: chooseMedia

Take or select a picture or video from user phone’s album.

Reference

Type

  1. (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

  1. Taro.chooseMedia({
  2. count: 9,
  3. mediaType: ['image','video'],
  4. sourceType: ['album', 'camera'],
  5. maxDuration: 30,
  6. camera: 'back',
  7. success: (res) => {
  8. console.log(res.tempFiles)
  9. console.log(res.type)
  10. }
  11. })

API Support

API WeChat Mini-Program H5 React Native
Taro.chooseMedia ✔️ ✔️