Media APIs

chooseImage

Choose an image from the camera or gallery of a device.

Overview

my.chooseImage allows users to select an image from their device's camera or photo gallery. The API returns file paths to the selected images.

Sample Code

my.chooseImage({
  success: (res) => {
    img.src = res.apFilePaths[0];
  },
});

Parameters

PropertyTypeRequiredDescription
sizeTypeStringArrayNoOriginal image, compressed image, both by default.
sourceTypeString ArrayNoCamera or album, ['camera','album'] by default.
successFunctionNoCallback function upon call success.
failFunctionNoCallback function upon call failure.
completeFunctionNoCallback function upon call completion (to be executed upon either call success or failure).

Success Callback Function

The incoming parameter is of the Object type with the following attributes:

PropertyTypeDescription
apFilePathsString ArrayImage file description.

Error Code

ErrorDescription
11User cancels operation.

Usage Notes

  • The sizeType parameter controls whether to return original or compressed images
  • The sourceType parameter lets you specify camera, album, or both
  • Users can cancel the image selection, triggering error code 11