The CameraRoll class lets you open an image browser so that the user can select a picture from the device media library. The CameraUI class lets you launch the device camera app so that the user can take a picture or video. In both cases the CameraRoll and CameraUI objects return the media via an event containing a media promise.
The options available for accessing the data in a media promise are different from one platform to another. For example, on Android, the media promise includes a
file property that references the source image file, but on iOS this property is always null—the source file is not accessible. The technique described in this article works on all platforms.
Getting the media promise
The first step is to request the image from either the CameraRoll or the CameraUI object. In both cases, you create the appropriate object, set up some event listeners, and then call the function that asks for the image. The runtime then returns the image in an event containing the media promise after the user has either chosen a picture from the device media library or taken a new picture with the camera.
The following code example sets up the event listeners necessary to handle the events that can be dispatched by a CameraRoll object and then calls the
browseForImage() method. When the user selects an image, the runtime calls an event handler function named,