1# Interface (MediaAssetDataHandler) 2 3> **NOTE** 4> 5> - The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version. 6> - The initial APIs of this interface are supported since API version 11. 7 8MediaAssetDataHandler is a media asset handler used to customize the media asset processing logic in **onDataPrepared**. 9 10**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 11 12## Modules to Import 13 14```ts 15import { photoAccessHelper } from '@kit.MediaLibraryKit'; 16``` 17 18## onDataPrepared<sup>11+</sup> 19 20onDataPrepared(data: T, map?: Map<string, string>): void 21 22Called when the requested media asset is ready. If an error occurs, **data** returned by the callback is **undefined**. Each media asset request corresponds to a callback. 23 24T supports the following data types: ArrayBuffer, [ImageSource](../apis-image-kit/arkts-apis-image-ImageSource.md), [MovingPhoto](arkts-apis-photoAccessHelper-MovingPhoto.md), and boolean. ArrayBuffer indicates the image or video asset data, [ImageSource](../apis-image-kit/arkts-apis-image-ImageSource.md) indicates the image source, [MovingPhoto](arkts-apis-photoAccessHelper-MovingPhoto.md) indicates a moving photo object, and boolean indicates whether the image or video is successfully written to the application sandbox directory. 25 26Information returned by **map**: 27 28| Map Key | Description| 29|----------|-------| 30| 'quality' | Image quality. The value **high** means high quality, and **low** means poor quality.| 31 32**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 33 34**Parameters** 35 36| Name | Type| Mandatory| Description | 37|------|---| ---- |-------------------------------------------------------------------------------| 38| data | T | Yes | Data of the image asset that is ready. It is of the generic type and supports the following data types: ArrayBuffer, [ImageSource](../apis-image-kit/arkts-apis-image-ImageSource.md), [MovingPhoto](arkts-apis-photoAccessHelper-MovingPhoto.md), and boolean.| 39| map<sup>12+</sup> | Map<string, string> | No | Additional information about the image asset, such as the image quality. Currently, only **quality** is supported.| 40 41**Example** 42 43```ts 44import { image } from '@kit.ImageKit'; 45 46class MediaHandler implements photoAccessHelper.MediaAssetDataHandler<image.ImageSource> { 47 onDataPrepared = (data: image.ImageSource, map: Map<string, string>) => { 48 if (data === undefined) { 49 console.error('Error occurred when preparing data'); 50 return; 51 } 52 // Customize the processing logic for ImageSource. 53 console.info('on image data prepared, photo quality is ' + map['quality']); 54 } 55} 56 57class MediaDataHandler implements photoAccessHelper.MediaAssetDataHandler<ArrayBuffer> { 58 onDataPrepared = (data: ArrayBuffer, map: Map<string, string>) => { 59 if (data === undefined) { 60 console.error('Error occurred when preparing data'); 61 return; 62 } 63 // Customize the processing logic for ArrayBuffer. 64 console.info('on image data prepared, photo quality is ' + map['quality']); 65 } 66} 67 68class MovingPhotoHandler implements photoAccessHelper.MediaAssetDataHandler<photoAccessHelper.MovingPhoto> { 69 onDataPrepared = (data: photoAccessHelper.MovingPhoto, map: Map<string, string>) => { 70 if (data === undefined) { 71 console.error('Error occurred when preparing data'); 72 return; 73 } 74 // Customize the processing logic for MovingPhoto. 75 console.info('on image data prepared, photo quality is ' + map['quality']); 76 } 77} 78``` 79