chooseImage(params: Object)

Requires:
BaseKit≥2.0.1@ray-js/ray≥0.3.23
Platforms:
iOSAndroid
import { chooseImage } from '@ray-js/ray';

// Promise usage
try {
  const res = await chooseImage({ ...params });
  console.log(res);
} catch (err) {
  console.log(err.errorMsg);
}

Description

Select images from the local album or take photos with the camera. You can use chooseMedia instead.
Permissions: [scope.camera, scope.writePhotosAlbum]
Related API: [chooseMedia]

Parameters

PropertyTypeRequiredDefaultDescriptionBaseKit Since
countnumberNo9Maximum number of images to select. Note: On Android 13 and above, the system image picker is used and this field has no effect-
imageTypestringNo-Filter image types; pass 'gif' to show only GIFs, pass 'image' to show non-GIF static images; if omitted or empty, no filtering by defaultv3.32.13
sizeTypestring[]No-Image size type; pass 'original' for the original image, 'compressed' for a compressed image-
sourceTypestring[]No-Source for selecting images ['album', 'camera']-
disableDismissAnimationAfterSelectbooleanNo-Whether to disable the animation when closing the interface after canceling image selectionv3.11.3
complete() => voidNo-Completion callback (executed on both success and failure)-
success(params: Object) => voidNo-Callback on successful API call-
fail(params: Object) => voidNo-Failure callback-
success callback parameters
PropertyTypeDescriptionBaseKit Since
tempFilePathsstring[]List of local temporary image file paths (local paths)v3.2.6
List of selected image file objects, including the local temporary file path path and file size size (in bytes)v3.2.6
fail callback parameters
PropertyTypeDescription
errorMsgstringError message
errorCodestring | numberError code
Error extension

Return Value

None

Examples

import { chooseImage } from '@ray-js/ray'

// Select images from the album or take photos (invokes the system picker; manual selection required)
chooseImage({
  count: 1,
  sizeType: ["compressed"],
  sourceType: ["album", "camera"],
  success: data => console.log("Selected images:", data.tempFilePaths),
  fail: error => console.error(error),
});