# @ohos.file.photoAccessHelper (Album Management) The **photoAccessHelper** module provides APIs for album management, including creating an album and accessing and modifying media data in an album. > **NOTE** > > 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. ## Modules to Import ```ts import { photoAccessHelper } from '@kit.MediaLibraryKit'; ``` ## photoAccessHelper.getPhotoAccessHelper getPhotoAccessHelper(context: Context): PhotoAccessHelper Obtains a **PhotoAccessHelper** instance for accessing and modifying media files in the album. **Model restriction**: This API can be used only in the stage model. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory| Description | | ------- | ------- | ---- | -------------------------- | | context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.| **Return value** | Type | Description | | ----------------------------- | :---- | | [PhotoAccessHelper](#photoaccesshelper) | **PhotoAccessHelper** instance obtained.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | **Example** ```ts // The phAccessHelper instance obtained is a global object. It is used by default in subsequent operations. If the code snippet is not added, an error will be reported indicating that phAccessHelper is not defined. let context = getContext(this); let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); ``` ## PhotoAccessHelper ### getAssets getAssets(options: FetchOptions, callback: AsyncCallback<FetchResult<PhotoAsset>>): void Obtains image and video assets. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Required permissions**: ohos.permission.READ_IMAGEVIDEO If the caller does not have the ohos.permission.READ_IMAGEVIDEO permission, use Picker to access the file and then call this API based on the URI obtained by Picker. For details, see [Obtaining an Image or Video by URI](../../media/medialibrary/photoAccessHelper-photoviewpicker.md#obtaining-an-image-or-video-by-uri). **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------ | ---- | ------------------------- | | options | [FetchOptions](#fetchoptions) | Yes | Options for fetching the image and video assets. | | callback | AsyncCallback<[FetchResult](#fetchresult)<[PhotoAsset](#photoasset)>> | Yes | Callback used to return the image and video assets obtained.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example() { console.info('getAssets'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; phAccessHelper.getAssets(fetchOptions, async (err, fetchResult) => { if (fetchResult !== undefined) { console.info('fetchResult success'); let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); if (photoAsset !== undefined) { console.info('photoAsset.displayName : ' + photoAsset.displayName); } } else { console.error(`fetchResult fail with error: ${err.code}, ${err.message}`); } }); } ``` ### getAssets getAssets(options: FetchOptions): Promise<FetchResult<PhotoAsset>> Obtains image and video assets. This API uses a promise to return the result. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Required permissions**: ohos.permission.READ_IMAGEVIDEO If the caller does not have the ohos.permission.READ_IMAGEVIDEO permission, use Picker to access the file and then call this API based on the URI obtained by Picker. For details, see [Obtaining an Image or Video by URI](../../media/medialibrary/photoAccessHelper-photoviewpicker.md#obtaining-an-image-or-video-by-uri). **Parameters** | Name | Type | Mandatory| Description | | ------- | ------------------- | ---- | ---------------- | | options | [FetchOptions](#fetchoptions) | Yes | Options for fetching the image and video assets. | **Return value** | Type | Description | | --------------------------- | -------------- | | Promise<[FetchResult](#fetchresult)<[PhotoAsset](#photoasset)>> | Promise used to return the image and video assets obtained.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example() { console.info('getAssets'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; try { let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); if (fetchResult !== undefined) { console.info('fetchResult success'); let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); if (photoAsset !== undefined) { console.info('photoAsset.displayName :' + photoAsset.displayName); } } } catch (err) { console.error(`getAssets failed, error: ${err.code}, ${err.message}`); } } ``` ### getBurstAssets12+ getBurstAssets(burstKey: string, options: FetchOptions): Promise<FetchResult<PhotoAsset>> Obtains burst assets. This API uses a promise to return the result. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Required permissions**: ohos.permission.READ_IMAGEVIDEO **Parameters** | Name | Type | Mandatory| Description | | ------- | ------------------- | ---- | ---------------- | | burstKey | string | Yes | UUID of a set of burst photos (**BURST_KEY** of [PhotoKeys](#photokeys)). | | options | [FetchOptions](#fetchoptions) | Yes | Options for fetching the burst photos. | **Return value** | Type | Description | | --------------------------- | -------------- | | Promise<[FetchResult](#fetchresult)<[PhotoAsset](#photoasset)>> | Promise used to return the result.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 201 | Permission denied. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | Internal system error. | **Example** ```ts import { photoAccessHelper } form '@kit.MediaLibraryKit'; import { dataSharePredicates } from '@kit.ArkData'; async function example() { console.info('getBurstAssets'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; // burstKey is a 36-bit UUID, which can be obtained from photoAccessHelper.PhotoKeys. let burstKey: string = "e719d696-09fa-44f8-ec3f215aa62a"; try { let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getBurstAssets(burstKey, fetchOptions); if (fetchResult !== undefined) { console.info('fetchResult success'); let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); if (photoAsset !== undefined) { console.info('photoAsset.displayName :' + photoAsset.displayName); } } } catch (err) { console.error(`getBurstAssets failed, error: ${err.code}, ${err.message}`); } } ``` ### createAsset createAsset(photoType: PhotoType, extension: string, options: CreateOptions, callback: AsyncCallback<string>): void Creates an image or video asset with the specified file type, file name extension, and options. This API uses an asynchronous callback to return the result. If the caller does not have the ohos.permission.WRITE_IMAGEVIDEO permission, you can create a media asset by using a security component. For details, see [Creating a Media Asset Using a Security Component](../../media/medialibrary/photoAccessHelper-savebutton.md). **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Required permissions**: ohos.permission.WRITE_IMAGEVIDEO **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------ | ---- | ------------------------- | | photoType | [PhotoType](#phototype) | Yes | Type of the file to create, which can be **IMAGE** or **VIDEO**. | | extension | string | Yes | File name extension, for example, **'jpg'**. | | options | [CreateOptions](#createoptions) | Yes | Options for creating the image or video asset, for example, **{title: 'testPhoto'}**. | | callback | AsyncCallback<string> | Yes | Callback used to return the URI of the created image or video.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** ```ts async function example() { console.info('createAssetDemo'); let photoType: photoAccessHelper.PhotoType = photoAccessHelper.PhotoType.IMAGE; let extension:string = 'jpg'; let options: photoAccessHelper.CreateOptions = { title: 'testPhoto' } phAccessHelper.createAsset(photoType, extension, options, (err, uri) => { if (uri !== undefined) { console.info('createAsset uri' + uri); console.info('createAsset successfully'); } else { console.error(`createAsset failed, error: ${err.code}, ${err.message}`); } }); } ``` ### createAsset createAsset(photoType: PhotoType, extension: string, callback: AsyncCallback<string>): void Creates an image or video asset with the specified file type and file name extension. This API uses an asynchronous callback to return the result. If the caller does not have the ohos.permission.WRITE_IMAGEVIDEO permission, you can create a media asset by using a security component. For details, see [Creating a Media Asset Using a Security Component](../../media/medialibrary/photoAccessHelper-savebutton.md). **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Required permissions**: ohos.permission.WRITE_IMAGEVIDEO **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------ | ---- | ------------------------- | | photoType | [PhotoType](#phototype) | Yes | Type of the file to create, which can be **IMAGE** or **VIDEO**. | | extension | string | Yes | File name extension, for example, **'jpg'**. | | callback | AsyncCallback<string> | Yes | Callback used to return the URI of the created image or video.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** ```ts async function example() { console.info('createAssetDemo'); let photoType: photoAccessHelper.PhotoType = photoAccessHelper.PhotoType.IMAGE; let extension: string = 'jpg'; phAccessHelper.createAsset(photoType, extension, (err, uri) => { if (uri !== undefined) { console.info('createAsset uri' + uri); console.info('createAsset successfully'); } else { console.error(`createAsset failed, error: ${err.code}, ${err.message}`); } }); } ``` ### createAsset createAsset(photoType: PhotoType, extension: string, options?: CreateOptions): Promise<string> Creates an image or video asset with the specified file type, file name extension, and options. This API uses a promise to return the result. If the caller does not have the ohos.permission.WRITE_IMAGEVIDEO permission, you can create a media asset by using a security component. For details, see [Creating a Media Asset Using a Security Component](../../media/medialibrary/photoAccessHelper-savebutton.md). **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Required permissions**: ohos.permission.WRITE_IMAGEVIDEO **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------ | ---- | ------------------------- | | photoType | [PhotoType](#phototype) | Yes | Type of the file to create, which can be **IMAGE** or **VIDEO**. | | extension | string | Yes | File name extension, for example, **'jpg'**. | | options | [CreateOptions](#createoptions) | No | Options for creating the image or video asset, for example, **{title: 'testPhoto'}**. | **Return value** | Type | Description | | --------------------------- | -------------- | | Promise<string> | Promise used to return the URI of the created image or video asset.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** ```ts async function example() { console.info('createAssetDemo'); try { let photoType: photoAccessHelper.PhotoType = photoAccessHelper.PhotoType.IMAGE; let extension: string = 'jpg'; let options: photoAccessHelper.CreateOptions = { title: 'testPhoto' } let uri: string = await phAccessHelper.createAsset(photoType, extension, options); console.info('createAsset uri' + uri); console.info('createAsset successfully'); } catch (err) { console.error(`createAsset failed, error: ${err.code}, ${err.message}`); } } ``` ### getAlbums getAlbums(type: AlbumType, subtype: AlbumSubtype, options: FetchOptions, callback: AsyncCallback<FetchResult<Album>>): void Obtains albums based on the specified options and album type. This API uses an asynchronous callback to return the result. Before the operation, ensure that the albums to obtain exist. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Required permissions**: ohos.permission.READ_IMAGEVIDEO **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------ | ---- | ------------------------- | | type | [AlbumType](#albumtype) | Yes | Type of the albums to obtain. | | subtype | [AlbumSubtype](#albumsubtype) | Yes | Subtype of the album. | | options | [FetchOptions](#fetchoptions) | Yes | Options for fetching the albums. | | callback | AsyncCallback<[FetchResult](#fetchresult)<[Album](#album)>> | Yes | Callback used to return the result.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example() { // Obtain the album named newAlbumName. console.info('getAlbumsDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); predicates.equalTo('album_name', 'newAlbumName'); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, fetchOptions, async (err, fetchResult) => { if (err) { console.error(`getAlbumsCallback failed with err: ${err.code}, ${err.message}`); return; } if (fetchResult === undefined) { console.error('getAlbumsCallback fetchResult is undefined'); return; } let album = await fetchResult.getFirstObject(); console.info('getAlbumsCallback successfully, albumName: ' + album.albumName); fetchResult.close(); }); } ``` ### getAlbums getAlbums(type: AlbumType, subtype: AlbumSubtype, callback: AsyncCallback<FetchResult<Album>>): void Obtains albums by type. This API uses an asynchronous callback to return the result. Before the operation, ensure that the albums to obtain exist. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Required permissions**: ohos.permission.READ_IMAGEVIDEO **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------ | ---- | ------------------------- | | type | [AlbumType](#albumtype) | Yes | Type of the albums to obtain. | | subtype | [AlbumSubtype](#albumsubtype) | Yes | Subtype of the album. | | callback | AsyncCallback<[FetchResult](#fetchresult)<[Album](#album)>> | Yes | Callback used to return the result.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** ```ts async function example() { // Obtain the system album VIDEO, which is preset by default. console.info('getAlbumsDemo'); phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.VIDEO, async (err, fetchResult) => { if (err) { console.error(`getAlbumsCallback failed with err: ${err.code}, ${err.message}`); return; } if (fetchResult === undefined) { console.error('getAlbumsCallback fetchResult is undefined'); return; } let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); console.info('getAlbumsCallback successfully, albumUri: ' + album.albumUri); fetchResult.close(); }); } ``` ### getAlbums getAlbums(type: AlbumType, subtype: AlbumSubtype, options?: FetchOptions): Promise<FetchResult<Album>> Obtains albums based on the specified options and album type. This API uses a promise to return the result. Before the operation, ensure that the albums to obtain exist. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Required permissions**: ohos.permission.READ_IMAGEVIDEO **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------ | ---- | ------------------------- | | type | [AlbumType](#albumtype) | Yes | Type of the albums to obtain. | | subtype | [AlbumSubtype](#albumsubtype) | Yes | Subtype of the album. | | options | [FetchOptions](#fetchoptions) | No | Options for fetching the albums. If this parameter is not specified, the albums are obtained based on the album type by default. | **Return value** | Type | Description | | --------------------------- | -------------- | | Promise<[FetchResult](#fetchresult)<[Album](#album)>> | Promise used to return the result.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; import { BusinessError } from '@kit.BasicServicesKit'; async function example() { // Obtain the album named newAlbumName. console.info('getAlbumsDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); predicates.equalTo('album_name', 'newAlbumName'); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, fetchOptions).then( async (fetchResult) => { if (fetchResult === undefined) { console.error('getAlbumsPromise fetchResult is undefined'); return; } let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); console.info('getAlbumsPromise successfully, albumName: ' + album.albumName); fetchResult.close(); }).catch((err: BusinessError) => { console.error(`getAlbumsPromise failed with err: ${err.code}, ${err.message}`); }); } ``` ### registerChange registerChange(uri: string, forChildUris: boolean, callback: Callback<ChangeData>) : void Registers listening for the specified URI. This API uses a callback to return the result. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory| Description | | --------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | | uri | string | Yes | URI of the photo asset, URI of the album, or [DefaultChangeUri](#defaultchangeuri).| | forChildUris | boolean | Yes | Whether to perform fuzzy listening.
If **uri** is the URI of an album, the value **true** means to listen for the changes of the files in the album; the value **false** means to listen for the changes of the album only.
If **uri** is the URI of a **photoAsset**, there is no difference between **true** and **false** for **forChildUris**.
If **uri** is **DefaultChangeUri**, **forChildUris** must be set to **true**. If **forChildUris** is **false**, the URI cannot be found and no message can be received.| | callback | Callback<[ChangeData](#changedata)> | Yes | Callback used to return the [ChangeData](#changedata).
**NOTE**
Multiple callback listeners can be registered for a URI. You can use [unRegisterChange](#unregisterchange) to unregister all listeners for the URI or a specified callback listener.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example() { console.info('registerChangeDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); if (photoAsset !== undefined) { console.info('photoAsset.displayName : ' + photoAsset.displayName); } let onCallback1 = (changeData: photoAccessHelper.ChangeData) => { console.info('onCallback1 success, changData: ' + JSON.stringify(changeData)); //file had changed, do something } let onCallback2 = (changeData: photoAccessHelper.ChangeData) => { console.info('onCallback2 success, changData: ' + JSON.stringify(changeData)); //file had changed, do something } // Register onCallback1. phAccessHelper.registerChange(photoAsset.uri, false, onCallback1); // Register onCallback2. phAccessHelper.registerChange(photoAsset.uri, false, onCallback2); await photoAccessHelper.MediaAssetChangeRequest.deleteAssets(context, [photoAsset]); } ``` ### unRegisterChange unRegisterChange(uri: string, callback?: Callback<ChangeData>): void Unregisters listening for the specified URI. Multiple callbacks can be registered for a URI for listening. You can use this API to unregister the listening of the specified callbacks or all callbacks. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | | uri | string | Yes | URI of the photo asset, URI of the album, or [DefaultChangeUri](#defaultchangeuri).| | callback | Callback<[ChangeData](#changedata)> | No | Callback to unregister. If this parameter is not specified, all the callbacks for listening for the URI will be canceled.
**NOTE**: The specified callback unregistered will not be invoked when the data changes.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example() { console.info('offDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); if (photoAsset !== undefined) { console.info('photoAsset.displayName : ' + photoAsset.displayName); } let onCallback1 = (changeData: photoAccessHelper.ChangeData) => { console.info('onCallback1 on'); } let onCallback2 = (changeData: photoAccessHelper.ChangeData) => { console.info('onCallback2 on'); } // Register onCallback1. phAccessHelper.registerChange(photoAsset.uri, false, onCallback1); // Register onCallback2. phAccessHelper.registerChange(photoAsset.uri, false, onCallback2); // Unregister the listening of onCallback1. phAccessHelper.unRegisterChange(photoAsset.uri, onCallback1); await photoAccessHelper.MediaAssetChangeRequest.deleteAssets(context, [photoAsset]); } ``` ### createDeleteRequest(deprecated) createDeleteRequest(uriList: Array<string>, callback: AsyncCallback<void>): void Creates a dialog box for deleting media files. This API uses an asynchronous callback to return the result. The deleted media files are moved to the trash. > **NOTE** > > This API is supported since API version 10 and deprecated since API version 11. Use [MediaAssetChangeRequest.deleteAssets](#deleteassets11-1) instead. **Required permissions**: ohos.permission.WRITE_IMAGEVIDEO **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | ---------- | | uriList | Array<string> | Yes | URIs of the media files to delete. A maximum of 300 media files can be deleted.| | callback | AsyncCallback<void> | Yes | Callback that returns no value.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example() { console.info('createDeleteRequestDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; try { let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); if (asset === undefined) { console.error('asset not exist'); return; } phAccessHelper.createDeleteRequest([asset.uri], (err) => { if (err === undefined) { console.info('createDeleteRequest successfully'); } else { console.error(`createDeleteRequest failed with error: ${err.code}, ${err.message}`); } }); } catch (err) { console.error(`fetch failed, error: ${err.code}, ${err.message}`); } } ``` ### createDeleteRequest(deprecated) createDeleteRequest(uriList: Array<string>): Promise<void> Creates a dialog box for deleting media files. This API uses a promise to return the result. The deleted media files are moved to the trash. > **NOTE** > > This API is supported since API version 10 and deprecated since API version 11. Use [MediaAssetChangeRequest.deleteAssets](#deleteassets11-1) instead. **Required permissions**: ohos.permission.WRITE_IMAGEVIDEO **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | ---------- | | uriList | Array<string> | Yes | URIs of the media files to delete. A maximum of 300 media files can be deleted.| **Return value** | Type | Description | | --------------------------------------- | ----------------- | | Promise<void>| Promise that returns no value.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example() { console.info('createDeleteRequestDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; try { let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); if (asset === undefined) { console.error('asset not exist'); return; } await phAccessHelper.createDeleteRequest([asset.uri]); console.info('createDeleteRequest successfully'); } catch (err) { console.error(`createDeleteRequest failed with error: ${err.code}, ${err.message}`); } } ``` ### applyChanges11+ applyChanges(mediaChangeRequest: MediaChangeRequest): Promise<void> Applies media changes. This API uses a promise to return the result. **Required permissions**: ohos.permission.WRITE_IMAGEVIDEO If the caller does not have the ohos.permission.WRITE_IMAGEVIDEO permission, you can create a media asset by using a security component. For details, see [Creating a Media Asset Using a Security Component](../../media/medialibrary/photoAccessHelper-savebutton.md). **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------ | ---- | ------------------------- | | mediaChangeRequest | [MediaChangeRequest](#mediachangerequest11) | Yes | Request for asset changes or album changes.| **Return value** | Type | Description | | --------------------------------------- | ----------------- | | Promise<void>| Promise that returns no value.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 201 | Permission denied. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | **Example** This API depends on the [MediaChangeRequest](#mediachangerequest11) object. For details about the sample code, see the examples of [MediaAssetChangeRequest](#mediaassetchangerequest11) and [MediaAlbumChangeRequest](#mediaalbumchangerequest11). ### release release(callback: AsyncCallback<void>): void Releases this **PhotoAccessHelper** instance. This API uses an asynchronous callback to return the result. Call this API when the APIs of the **PhotoAccessHelper** instance are no longer used. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | -------------------- | | callback | AsyncCallback<void> | Yes | Callback used to return the result.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** ```ts async function example() { console.info('releaseDemo'); phAccessHelper.release((err) => { if (err !== undefined) { console.error(`release failed. error: ${err.code}, ${err.message}`); } else { console.info('release ok.'); } }); } ``` ### release release(): Promise<void> Releases this **PhotoAccessHelper** instance. This API uses a promise to return the result. Call this API when the APIs of the **PhotoAccessHelper** instance are no longer used. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Return value** | Type | Description | | ------------------- | --------------------------------- | | Promise<void> | Promise that returns no value.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** ```ts async function example() { console.info('releaseDemo'); try { await phAccessHelper.release(); console.info('release ok.'); } catch (err) { console.error(`release failed. error: ${err.code}, ${err.message}`); } } ``` ### showAssetsCreationDialog12+ showAssetsCreationDialog(srcFileUris: Array<string>, photoCreationConfigs: Array<PhotoCreationConfig>): Promise<Array<string>> Shows the dialog box for the user to confirm whether to save the photos or videos. If the user agrees to save the images or videos, a list of URIs granted with the save permission is returned. The list takes effect permanently, and the application can write the images or videos based on the URIs. If the user refuses to save the images or videos, an empty list is returned. **Atomic service API**: This API can be used in atomic services since API version 12. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory| Description | | -------- |----------------------------------------------------------------------| ---- | ------------------------- | | srcFileUris | Array<string> | Yes| [URIs](../../file-management/user-file-uri-intro.md#media-file-uri) of the images or videos to be saved to the media library.
**NOTE**: Only image and video URIs are supported.| | photoCreationConfigs | Array<[PhotoCreationConfig](#photocreationconfig12)> | Yes| Configuration for saving the images or videos, including the names of the files to be saved. The value must be consistent with that of **srcFileUris**.| **Return value** | Type | Description | | --------------------------------------- | ----------------- | | Promise<Array<string>> | Promise used to return a URI list. The URIs are granted with the permission for the application to write data.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | Internal system error | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; import { photoAccessHelper } from '@kit.MediaLibraryKit'; async function example() { console.info('ShowAssetsCreationDialogDemo.'); try { // Obtain the sandbox URIs of the images or videos to be saved to the media library. let srcFileUris: Array = [ 'file://fileUriDemo1' // The URI here is an example only. ]; let photoCreationConfigs: Array = [ { title: 'test2', // Optional. fileNameExtension: 'jpg', photoType: photoAccessHelper.PhotoType.IMAGE, subtype: photoAccessHelper.PhotoSubtype.DEFAULT, // Optional. } ]; let desFileUris: Array = await phAccessHelper.showAssetsCreationDialog(srcFileUris, photoCreationConfigs); console.info('showAssetsCreationDialog success, data is ' + desFileUris); } catch (err) { console.error('showAssetsCreationDialog failed, errCode is ' + err.code + ', errMsg is ' + err.message); } } ``` ### createAssetWithShortTermPermission12+ createAssetWithShortTermPermission(photoCreationConfig: PhotoCreationConfig): Promise<string> Creates an asset with a temporary permission of the given period. When this API is called by an application for the first time, a dialog box will be displayed for the user to confirm whether to save the asset. If the user agrees to save the asset, the asset instance will be created and the file URI granted with the save permission will be returned. The application can write the asset based on the URI within 5 minutes after the user agrees to save the asset. If the same application calls this API again within the 5 minutes, the authorized URI can be automatically returned without the need to display the conformation dialog box. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Required permissions**: ohos.permission.SHORT_TERM_WRITE_IMAGEVIDEO **Parameters** | Name | Type | Mandatory| Description | | -------- |----------------------------------------------------------------------| ---- | ------------------------- | | photoCreationConfig | [PhotoCreationConfig](#photocreationconfig12); | Yes| Configuration for saving a media asset (image or video) to the media library, including the file name.| **Return value** | Type | Description | | --------------------------------------- | ----------------- | | Promise<string> | Promise used to return the URI of the asset saved. The URIs are granted with the permission for the application to write data.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 201 | Permission denied | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | Internal system error | **Example** ```ts import { fileIo } from '@kit.CoreFileKit'; async function example() { console.info('createAssetWithShortTermPermissionDemo.'); try { let photoCreationConfig: photoAccessHelper.PhotoCreationConfig = { title: '123456', fileNameExtension: 'jpg', photoType: photoAccessHelper.PhotoType.IMAGE, subtype: photoAccessHelper.PhotoSubtype.DEFAULT, }; let resultUri: string = await phAccessHelper.createAssetWithShortTermPermission(photoCreationConfig); let resultFile: fileIo.File = fileIo.openSync(resultUri, fileIo.OpenMode.READ_WRITE); // Use the actual URI and file size. let srcFile: fileIo.File = fileIo.openSync("file://test.jpg", fileIo.OpenMode.READ_ONLY); let bufSize: number = 2000000; let readSize: number = 0; let buf = new ArrayBuffer(bufSize); let readLen = fileIo.readSync(srcFile.fd, buf, { offset: readSize, length: bufSize }); if (readLen > 0) { readSize += readLen; fileIo.writeSync(resultFile.fd, buf, { length: readLen }); } fileIo.closeSync(srcFile); fileIo.closeSync(resultFile); } catch (err) { console.error('createAssetWithShortTermPermission failed, errCode is ' + err.code + ', errMsg is ' + err.message); } } ``` ### requestPhotoUrisReadPermission14+ requestPhotoUrisReadPermission(srcFileUris: Array<string>): Promise<Array<string>> Grants the save permission for URIs. This API uses a promise to return the result. **Atomic service API**: This API can be used in atomic services since API version 14. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory| Description | | -------- |----------------------------------------------------------------------| ---- | ------------------------- | | srcFileUris | Array<string> | Yes| [URIs](../../file-management/user-file-uri-intro.md#media-file-uri) of the images or videos to be granted with the permission.
**NOTE**: Only image and video URIs are supported.| **Return value** | Type | Description | | --------------------------------------- | ----------------- | | Promise<Array<string>> | Promise used to return the URIs granted with the save permission.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | Internal system error | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; import { photoAccessHelper } from '@kit.MediaLibraryKit'; async function example() { console.info('requestPhotoUrisReadPermissionDemo.'); try { let phAccessHelper: photoAccessHelper.PhotoAccessHelper = photoAccessHelper.getPhotoAccessHelper(this.context); // Obtain the URIs of the images or videos to be granted with the permission. let srcFileUris: Array = [ 'file://fileUriDemo1' // The URI here is an example only. ]; let desFileUris: Array = await phAccessHelper.requestPhotoUrisReadPermission(srcFileUris); console.info('requestPhotoUrisReadPermission success, data is ' + desFileUris); } catch (err) { console.error('requestPhotoUrisReadPermission failed, errCode is ' + err.code + ', errMsg is ' + err.message); } } ``` ## PhotoAsset Provides APIs for encapsulating file asset attributes. ### Properties **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core | Name | Type | Readable| Writable| Description | | ------------------------- | ------------------------ | ---- | ---- | ------------------------------------------------------ | | uri | string | Yes | No | Media asset URI, for example, **file://media/Photo/1/IMG_datetime_0001/displayName.jpg**. For details, see [Media File URI](../../file-management/user-file-uri-intro.md#media-file-uri).
**Atomic service API**: This API can be used in atomic services since API version 12. | | photoType | [PhotoType](#phototype) | Yes | No | Type of the file. | | displayName | string | Yes | No | File name, including the file name extension, to display. | ### get get(member: string): MemberType Obtains a **PhotoAsset** member parameter. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory | Description | | -------- | ------------------------- | ---- | ----- | | member | string | Yes | Name of the member parameter to obtain. Except **'uri'**, **'media_type'**, **'subtype'**, and **'display_name'**, you need to pass in [PhotoKeys](#photokeys) in **fetchColumns** in **get()**. For example, to obtain the title attribute, set **fetchColumns: ['title']**.| **Return value** | Type | Description | | ------------------- | --------------------------------- | | [MemberType](#membertype) | **PhotoAsset** member parameter obtained.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900020 | Invalid argument. | | 14000014 | Member is not a valid PhotoKey. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example() { console.info('photoAssetGetDemo'); try { let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: ['title'], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); let title: photoAccessHelper.PhotoKeys = photoAccessHelper.PhotoKeys.TITLE; let photoAssetTitle: photoAccessHelper.MemberType = photoAsset.get(title.toString()); console.info('photoAsset Get photoAssetTitle = ', photoAssetTitle); } catch (err) { console.error(`release failed. error: ${err.code}, ${err.message}`); } } ``` ### set set(member: string, value: string): void Sets a **PhotoAsset** member parameter. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory | Description | | -------- | ------------------------- | ---- | ----- | | member | string | Yes | Name of the member parameter to set. For example, **[PhotoKeys](#photokeys).TITLE**.| | value | string | Yes | Member parameter to set. Only the value of **[PhotoKeys](#photokeys).TITLE** can be modified.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900020 | Invalid argument. | | 14000014 | Member is not a valid PhotoKey. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example() { console.info('photoAssetSetDemo'); try { let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: ['title'], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); let title: string = photoAccessHelper.PhotoKeys.TITLE.toString(); photoAsset.set(title, 'newTitle'); } catch (err) { console.error(`release failed. error: ${err.code}, ${err.message}`); } } ``` ### commitModify commitModify(callback: AsyncCallback<void>): void Commits the modification on the file metadata to the database. This API uses an asynchronous callback to return the result. **Required permissions**: ohos.permission.WRITE_IMAGEVIDEO **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory | Description | | -------- | ------------------------- | ---- | ----- | | callback | AsyncCallback<void> | Yes | Callback that returns no value.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000001 | Invalid display name. | | 14000011 | System inner fail. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example() { console.info('commitModifyDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: ['title'], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); let title: string = photoAccessHelper.PhotoKeys.TITLE.toString(); let photoAssetTitle: photoAccessHelper.MemberType = photoAsset.get(title); console.info('photoAsset get photoAssetTitle = ', photoAssetTitle); photoAsset.set(title, 'newTitle2'); photoAsset.commitModify((err) => { if (err === undefined) { let newPhotoAssetTitle: photoAccessHelper.MemberType = photoAsset.get(title); console.info('photoAsset get newPhotoAssetTitle = ', newPhotoAssetTitle); } else { console.error(`commitModify failed, error: ${err.code}, ${err.message}`); } }); } ``` ### commitModify commitModify(): Promise<void> Commits the modification on the file metadata to the database. This API uses a promise to return the result. **Required permissions**: ohos.permission.WRITE_IMAGEVIDEO **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Return value** | Type | Description | | ------------------- | ---------- | | Promise<void> | Promise that returns no value.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000001 | Invalid display name. | | 14000011 | System inner fail. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example() { console.info('commitModifyDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: ['title'], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); let title: string = photoAccessHelper.PhotoKeys.TITLE.toString(); let photoAssetTitle: photoAccessHelper.MemberType = photoAsset.get(title); console.info('photoAsset get photoAssetTitle = ', photoAssetTitle); photoAsset.set(title, 'newTitle3'); try { await photoAsset.commitModify(); let newPhotoAssetTitle: photoAccessHelper.MemberType = photoAsset.get(title); console.info('photoAsset get newPhotoAssetTitle = ', newPhotoAssetTitle); } catch (err) { console.error(`release failed. error: ${err.code}, ${err.message}`); } } ``` ### getReadOnlyFd(deprecated) getReadOnlyFd(callback: AsyncCallback<number>): void Opens this file in read-only mode. This API uses an asynchronous callback to return the result. > **NOTE** > > - This API is supported since API version 10 and deprecated since API version 11. For security purposes, the API for obtaining the media file handle is no longer provided. > - The returned FD must be closed when it is not required. **Required permissions**: ohos.permission.READ_IMAGEVIDEO **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory | Description | | -------- | --------------------------- | ---- | ----------------------------------- | | callback | AsyncCallback<number> | Yes | Callback used to return the file descriptor (FD) of the file opened. | **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** ```ts async function example() { console.info('getReadOnlyFdDemo'); // Ensure that there are images and video files in the device. let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let assetResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); let photoAsset: photoAccessHelper.PhotoAsset = await assetResult.getFirstObject(); photoAsset.getReadOnlyFd((err, fd) => { if (fd !== undefined) { console.info('File fd' + fd); photoAsset.close(fd); } else { console.error(`getReadOnlyFd err: ${err.code}, ${err.message}`); } }); } ``` ### getReadOnlyFd(deprecated) getReadOnlyFd(): Promise<number> Opens this file in read-only mode. This API uses a promise to return the result. > **NOTE** > > - This API is supported since API version 10 and deprecated since API version 11. For security purposes, the API for obtaining the media file handle is no longer provided. > - The returned FD must be closed when it is not required. **Required permissions**: ohos.permission.READ_IMAGEVIDEO **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Return value** | Type | Description | | --------------------- | ------------- | | Promise<number> | Promise used to return the FD of the file opened.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** ```ts async function example() { console.info('getReadOnlyFdDemo'); try { // Ensure that there are images and video files in the device. let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let assetResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); let photoAsset: photoAccessHelper.PhotoAsset = await assetResult.getFirstObject(); let fd: number = await photoAsset.getReadOnlyFd(); if (fd !== undefined) { console.info('File fd' + fd); photoAsset.close(fd); } else { console.error('getReadOnlyFd fail'); } } catch (err) { console.error(`getReadOnlyFd demo err: ${err.code}, ${err.message}`); } } ``` ### close(deprecated) close(fd: number, callback: AsyncCallback<void>): void Closes a file. This API uses an asynchronous callback to return the result. > **NOTE** > > - This API is supported since API version 10 and deprecated since API version 11. > - For security purposes, the API for obtaining the media file handle is no longer provided, and the corresponding **close** API is also deprecated. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory | Description | | -------- | ------------------------- | ---- | ----- | | fd | number | Yes | FD of the file to close.| | callback | AsyncCallback<void> | Yes | Callback that returns no value.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example() { console.info('closeDemo'); try { let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); let fd: number = await photoAsset.open('rw'); console.info('file fd', fd); photoAsset.close(fd, (err) => { if (err === undefined) { console.info('asset close succeed.'); } else { console.error(`close failed, error: ${err.code}, ${err.message}`); } }); } catch (err) { console.error(`close failed, error: ${err.code}, ${err.message}`); } } ``` ### close(deprecated) close(fd: number): Promise<void> Closes a file. This API uses a promise to return the result. > **NOTE** > > This API is supported since API version 10 and deprecated since API version 11. For security purposes, the API for obtaining the media file handle is no longer provided, and the corresponding **close** API is also deprecated. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory | Description | | ---- | ------ | ---- | ----- | | fd | number | Yes | FD of the file to close.| **Return value** | Type | Description | | ------------------- | ---------- | | Promise<void> | Promise that returns no value.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example() { console.info('closeDemo'); try { let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); let fd = await asset.open('rw'); console.info('file fd', fd); await asset.close(fd); console.info('asset close succeed.'); } catch (err) { console.error(`close failed, error: ${err.code}, ${err.message}`); } } ``` ### getThumbnail getThumbnail(callback: AsyncCallback<image.PixelMap>): void Obtains the thumbnail of this file. This API uses an asynchronous callback to return the result. **Required permissions**: ohos.permission.READ_IMAGEVIDEO **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory | Description | | -------- | ----------------------------------- | ---- | ---------------- | | callback | AsyncCallback<[image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)> | Yes | Callback used to return the PixelMap of the thumbnail.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example() { console.info('getThumbnailDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); console.info('asset displayName = ', asset.displayName); asset.getThumbnail((err, pixelMap) => { if (err === undefined) { console.info('getThumbnail successful ' + pixelMap); } else { console.error(`getThumbnail fail with error: ${err.code}, ${err.message}`); } }); } ``` ### getThumbnail getThumbnail(size: image.Size, callback: AsyncCallback<image.PixelMap>): void Obtains the file thumbnail of the given size. This API uses an asynchronous callback to return the result. **Required permissions**: ohos.permission.READ_IMAGEVIDEO **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory | Description | | -------- | ----------------------------------- | ---- | ---------------- | | size | [image.Size](../apis-image-kit/js-apis-image.md#size) | Yes | Size of the thumbnail. | | callback | AsyncCallback<[image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)> | Yes | Callback used to return the PixelMap of the thumbnail.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; import { image } from '@kit.ImageKit'; async function example() { console.info('getThumbnailDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let size: image.Size = { width: 720, height: 720 }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); let asset = await fetchResult.getFirstObject(); console.info('asset displayName = ', asset.displayName); asset.getThumbnail(size, (err, pixelMap) => { if (err === undefined) { console.info('getThumbnail successful ' + pixelMap); } else { console.error(`getThumbnail fail with error: ${err.code}, ${err.message}`); } }); } ``` ### getThumbnail getThumbnail(size?: image.Size): Promise<image.PixelMap> Obtains the file thumbnail of the given size. This API uses a promise to return the result. **Required permissions**: ohos.permission.READ_IMAGEVIDEO **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory | Description | | ---- | -------------- | ---- | ----- | | size | [image.Size](../apis-image-kit/js-apis-image.md#size) | No | Size of the thumbnail.| **Return value** | Type | Description | | ----------------------------- | --------------------- | | Promise<[image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)> | Promise used to return the PixelMap of the thumbnail.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; import { image } from '@kit.ImageKit'; import { BusinessError } from '@kit.BasicServicesKit'; async function example() { console.info('getThumbnailDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let size: image.Size = { width: 720, height: 720 }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); let asset = await fetchResult.getFirstObject(); console.info('asset displayName = ', asset.displayName); asset.getThumbnail(size).then((pixelMap) => { console.info('getThumbnail successful ' + pixelMap); }).catch((err: BusinessError) => { console.error(`getThumbnail fail with error: ${err.code}, ${err.message}`); }); } ``` ### clone14+ clone(title: string): Promise<PhotoAsset> Clones a media asset. The file name can be set, but the file type cannot be changed. **Required permissions**: ohos.permission.WRITE\_IMAGEVIDEO **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory | Description | | ---------- | ------- | ---- | ---------------------------------- | | title| string | Yes | Title of the cloned asset. The title must meet the following requirements:
- It does not contain a file name extension.
- The file name, which is in the format of title+file name extension, does not exceed 255 characters.
- The title does not contain any of the following characters:\ / : * ? " ' ` < > \| { } [ ] | **Return value** | Type | Description | | ------------------- | ----------------------- | | Promise<PhotoAsset> | Promise used to return the [PhotoAsset](#photoasset) cloned.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID | Error Message | | :------- | :-------------------------------- | | 201 | Permission denied. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | Internal system error. It is recommended to retry and check the logs.Possible causes: 1. Database corrupted; 2. The file system is abnormal; 3. The IPC request timed out. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; import { systemDateTime } from '@kit.BasicServicesKit'; async function example() { let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; try { let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); let title: string = systemDateTime.getTime().toString(); let newAsset: photoAccessHelper.PhotoAsset = await photoAsset.clone(title); console.info('get new asset successfully'); } catch (error) { console.error(`failed to get new asset. message = ${error.code}, ${error.message}`); } } ``` ## PhotoViewPicker Provides APIs for the user to select images and videos. Before using the APIs of **PhotoViewPicker**, you need to create a **PhotoViewPicker** instance. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Example** ```ts let photoPicker = new photoAccessHelper.PhotoViewPicker(); ``` ### select select(option?: PhotoSelectOptions) : Promise<PhotoSelectResult> Starts a **photoPicker** page for the user to select one or more images or videos. This API uses a promise to return the result. You can pass in **PhotoSelectOptions** to specify the media file type and the maximum number of files to select. **NOTE**
The **photoUris** in the **PhotoSelectResult** object returned by this API can be used only by calling [photoAccessHelper.getAssets()](#getassets) with temporary authorization. For details, see [Using a Media File URI](../../file-management/user-file-uri-intro.md#using-a-media-file-uri). **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory| Description | | ------- | ------- | ---- | -------------------------- | | option | [PhotoSelectOptions](#photoselectoptions) | No | Options for selecting files. If this parameter is not specified, up to 50 images and videos are selected by default.| **Return value** | Type | Description | | ----------------------------- | :---- | | Promise<[PhotoSelectResult](#photoselectresult)> | Promise return information about the images or videos selected.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900042 | Unknown error. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; async function example01() { try { let PhotoSelectOptions = new photoAccessHelper.PhotoSelectOptions(); PhotoSelectOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE; PhotoSelectOptions.maxSelectNumber = 5; let photoPicker = new photoAccessHelper.PhotoViewPicker(); photoPicker.select(PhotoSelectOptions).then((PhotoSelectResult: photoAccessHelper.PhotoSelectResult) => { console.info('PhotoViewPicker.select successfully, PhotoSelectResult uri: ' + JSON.stringify(PhotoSelectResult)); }).catch((err: BusinessError) => { console.error(`PhotoViewPicker.select failed with err: ${err.code}, ${err.message}`); }); } catch (error) { let err: BusinessError = error as BusinessError; console.error(`PhotoViewPicker failed with err: ${err.code}, ${err.message}`); } } ``` ### select select(option: PhotoSelectOptions, callback: AsyncCallback<PhotoSelectResult>) : void Starts a **photoPicker** page for the user to select one or more images or videos. This API uses an asynchronous callback to return the result. You can pass in **PhotoSelectOptions** to specify the media file type and the maximum number of files to select. **NOTE**
The **photoUris** in the **PhotoSelectResult** object returned by this API can be used only by calling [photoAccessHelper.getAssets()](#getassets) with temporary authorization. For details, see [Using a Media File URI](../../file-management/user-file-uri-intro.md#using-a-media-file-uri). **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory| Description | | ------- | ------- | ---- | -------------------------- | | option | [PhotoSelectOptions](#photoselectoptions) | Yes | Options for selecting images or videos.| | callback | AsyncCallback<[PhotoSelectResult](#photoselectresult)> | Yes | Callback used to return information about the images or videos selected.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900042 | Unknown error. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; async function example02() { try { let PhotoSelectOptions = new photoAccessHelper.PhotoSelectOptions(); PhotoSelectOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE; PhotoSelectOptions.maxSelectNumber = 5; let photoPicker = new photoAccessHelper.PhotoViewPicker(); photoPicker.select(PhotoSelectOptions, (err: BusinessError, PhotoSelectResult: photoAccessHelper.PhotoSelectResult) => { if (err) { console.error(`PhotoViewPicker.select failed with err: ${err.code}, ${err.message}`); return; } console.info('PhotoViewPicker.select successfully, PhotoSelectResult uri: ' + JSON.stringify(PhotoSelectResult)); }); } catch (error) { let err: BusinessError = error as BusinessError; console.error(`PhotoViewPicker failed with err: ${err.code}, ${err.message}`); } } ``` ### select select(callback: AsyncCallback<PhotoSelectResult>) : void Starts a **photoPicker** page for the user to select one or more images or videos. This API uses an asynchronous callback to return the result. **NOTE**
The **photoUris** in the **PhotoSelectResult** object returned by this API can be used only by calling [photoAccessHelper.getAssets()](#getassets) with temporary authorization. For details, see [Using a Media File URI](../../file-management/user-file-uri-intro.md#using-a-media-file-uri). **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory| Description | | ------- | ------- | ---- | -------------------------- | | callback | AsyncCallback<[PhotoSelectResult](#photoselectresult)> | Yes | Callback used to return information about the images or videos selected.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 13900042 | Unknown error. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; async function example03() { try { let photoPicker = new photoAccessHelper.PhotoViewPicker(); photoPicker.select((err: BusinessError, PhotoSelectResult: photoAccessHelper.PhotoSelectResult) => { if (err) { console.error(`PhotoViewPicker.select failed with err: ${err.code}, ${err.message}`); return; } console.info('PhotoViewPicker.select successfully, PhotoSelectResult uri: ' + JSON.stringify(PhotoSelectResult)); }); } catch (error) { let err: BusinessError = error as BusinessError; console.error(`PhotoViewPicker failed with err: ${err.code}, ${err.message}`); } } ``` ## FetchResult Provides APIs to manage the file retrieval result. ### getCount getCount(): number Obtains the total number of files in the result set. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Return value** | Type | Description | | ------ | -------- | | number | Returns the total number of files obtained.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example() { console.info('getCountDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); let fetchCount = fetchResult.getCount(); console.info('fetchCount = ', fetchCount); } ``` ### isAfterLast isAfterLast(): boolean Checks whether the cursor is in the last row of the result set. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Return value** | Type | Description | | ------- | ---------------------------------- | | boolean | Returns **true** if the cursor is in the last row of the result set; returns **false** otherwise.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example() { let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); let fetchCount = fetchResult.getCount(); console.info('count:' + fetchCount); let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getLastObject(); if (fetchResult.isAfterLast()) { console.info('photoAsset isAfterLast displayName = ', photoAsset.displayName); } else { console.info('photoAsset not isAfterLast.'); } } ``` ### close close(): void Closes this **FetchFileResult** instance to invalidate it. After this instance is released, the APIs in this instance cannot be invoked. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example() { console.info('fetchResultCloseDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; try { let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); fetchResult.close(); console.info('close succeed.'); } catch (err) { console.error(`close fail. error: ${err.code}, ${err.message}`); } } ``` ### getFirstObject getFirstObject(callback: AsyncCallback<T>): void Obtains the first file asset in the result set. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | --------------------------------------------- | ---- | ------------------------------------------- | | callback | AsyncCallback<T> | Yes | Callback used to return the first file asset obtained.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example() { console.info('getFirstObjectDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); fetchResult.getFirstObject((err, photoAsset) => { if (photoAsset !== undefined) { console.info('photoAsset displayName: ', photoAsset.displayName); } else { console.error(`photoAsset failed with err:${err.code}, ${err.message}`); } }); } ``` ### getFirstObject getFirstObject(): Promise<T> Obtains the first file asset in the result set. This API uses a promise to return the result. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Return value** | Type | Description | | --------------------------------------- | -------------------------- | | Promise<T> | Promise used to return the first object in the result set.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example() { console.info('getFirstObjectDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); console.info('photoAsset displayName: ', photoAsset.displayName); } ``` ### getNextObject getNextObject(callback: AsyncCallback<T>): void Obtains the next file asset in the result set. This API uses an asynchronous callback to return the result. Before using this API, you must use [isAfterLast()](#isafterlast) to check whether the current position is the end of the result set. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory| Description | | --------- | --------------------------------------------- | ---- | ----------------------------------------- | | callback | AsyncCallback<T> | Yes | Callback used to return the next file asset.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example() { console.info('getNextObjectDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); await fetchResult.getFirstObject(); if (!fetchResult.isAfterLast()) { fetchResult.getNextObject((err, photoAsset) => { if (photoAsset !== undefined) { console.info('photoAsset displayName: ', photoAsset.displayName); } else { console.error(`photoAsset failed with err: ${err.code}, ${err.message}`); } }); } } ``` ### getNextObject getNextObject(): Promise<T> Obtains the next file asset in the result set. This API uses a promise to return the result. Before using this API, you must use [isAfterLast()](#isafterlast) to check whether the current position is the end of the result set. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Return value** | Type | Description | | --------------------------------------- | ----------------- | | Promise<T> | Promise used to return the next object in the result set.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example() { console.info('getNextObjectDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); await fetchResult.getFirstObject(); if (!fetchResult.isAfterLast()) { let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getNextObject(); console.info('photoAsset displayName: ', photoAsset.displayName); } } ``` ### getLastObject getLastObject(callback: AsyncCallback<T>): void Obtains the last file asset in the result set. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | --------------------------------------------- | ---- | --------------------------- | | callback | AsyncCallback<T> | Yes | Callback used to return the last file asset obtained.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example() { console.info('getLastObjectDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); fetchResult.getLastObject((err, photoAsset) => { if (photoAsset !== undefined) { console.info('photoAsset displayName: ', photoAsset.displayName); } else { console.error(`photoAsset failed with err: ${err.code}, ${err.message}`); } }); } ``` ### getLastObject getLastObject(): Promise<T> Obtains the last file asset in the result set. This API uses a promise to return the result. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Return value** | Type | Description | | --------------------------------------- | ----------------- | | Promise<T> | Promise used to return the last object in the result set.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example() { console.info('getLastObjectDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getLastObject(); console.info('photoAsset displayName: ', photoAsset.displayName); } ``` ### getObjectByPosition getObjectByPosition(index: number, callback: AsyncCallback<T>): void Obtains a file asset with the specified index in the result set. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------------------------- | ---- | ------------------ | | index | number | Yes | Index of the file asset to obtain. The value starts from **0**. | | callback | AsyncCallback<T> | Yes | Callback used to return the file asset obtained.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example() { console.info('getObjectByPositionDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); fetchResult.getObjectByPosition(0, (err, photoAsset) => { if (photoAsset !== undefined) { console.info('photoAsset displayName: ', photoAsset.displayName); } else { console.error(`photoAsset failed with err: ${err.code}, ${err.message}`); } }); } ``` ### getObjectByPosition getObjectByPosition(index: number): Promise<T> Obtains a file asset with the specified index in the result set. This API uses a promise to return the result. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory | Description | | ----- | ------ | ---- | -------------- | | index | number | Yes | Index of the file asset to obtain. The value starts from **0**.| **Return value** | Type | Description | | --------------------------------------- | ----------------- | | Promise<T> | Promise used to return the file asset obtained.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example() { console.info('getObjectByPositionDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getObjectByPosition(0); console.info('photoAsset displayName: ', photoAsset.displayName); } ``` ### getAllObjects getAllObjects(callback: AsyncCallback<Array<T>>): void Obtains all the file assets in the result set. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | --------------------------------------------- | ---- | ------------------------------------------- | | callback | AsyncCallback<Array<T>> | Yes | Callback used to return an array of all file assets in the result set.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example() { console.info('getAllObjectDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); fetchResult.getAllObjects((err, photoAssetList) => { if (photoAssetList !== undefined) { console.info('photoAssetList length: ', photoAssetList.length); } else { console.error(`photoAssetList failed with err:${err.code}, ${err.message}`); } }); } ``` ### getAllObjects getAllObjects(): Promise<Array<T>> Obtains all the file assets in the result set. This API uses a promise to return the result. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Return value** | Type | Description | | --------------------------------------- | -------------------------- | | Promise<Array<T>> | Promise used to return an array of all file assets in the result set.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example() { console.info('getAllObjectDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); let photoAssetList: Array = await fetchResult.getAllObjects(); console.info('photoAssetList length: ', photoAssetList.length); } ``` ## Album Provides APIs to manage albums. ### Properties **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core | Name | Type | Readable | Writable | Description | | ------------ | ------ | ---- | ---- | ------- | | albumType | [AlbumType](#albumtype) | Yes | No | Type of the album. | | albumSubtype | [AlbumSubtype](#albumsubtype) | Yes | No | Subtype of the album. | | albumName | string | Yes | Yes for a user album; no for a system album. | Name of the album. | | albumUri | string | Yes | No | URI of the album. | | count | number | Yes | No | Number of files in the album.| | coverUri | string | Yes | No | URI of the cover file of the album.| | imageCount11+ | number | Yes | No | Number of images in the album.| | videoCount11+ | number | Yes | No | Number of videos in the album.| ### getAssets getAssets(options: FetchOptions, callback: AsyncCallback<FetchResult<PhotoAsset>>): void Obtains image and video assets. This API uses an asynchronous callback to return the result. **Required permissions**: ohos.permission.READ_IMAGEVIDEO **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | ---------- | | options | [FetchOptions](#fetchoptions) | Yes | Options for fetching the assets.| | callback | AsyncCallback<[FetchResult](#fetchresult)<[PhotoAsset](#photoasset)>> | Yes | Callback used to return the image and video assets obtained.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example() { console.info('albumGetAssetsDemoCallback'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let albumFetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let albumList: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, albumFetchOptions); let album: photoAccessHelper.Album = await albumList.getFirstObject(); album.getAssets(fetchOption, (err, albumFetchResult) => { if (albumFetchResult !== undefined) { console.info('album getAssets successfully, getCount: ' + albumFetchResult.getCount()); } else { console.error(`album getAssets failed with error: ${err.code}, ${err.message}`); } }); } ``` ### getAssets getAssets(options: FetchOptions): Promise<FetchResult<PhotoAsset>> Obtains image and video assets. This API uses a promise to return the result. **Required permissions**: ohos.permission.READ_IMAGEVIDEO **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | ---------- | | options | [FetchOptions](#fetchoptions) | Yes | Options for fetching the assets.| **Return value** | Type | Description | | --------------------------------------- | ----------------- | | Promise<[FetchResult](#fetchresult)<[PhotoAsset](#photoasset)>> | Promise used to return the image and video assets obtained.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; import { BusinessError } from '@kit.BasicServicesKit'; async function example() { console.info('albumGetAssetsDemoPromise'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let albumFetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let albumList: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, albumFetchOptions); let album: photoAccessHelper.Album = await albumList.getFirstObject(); album.getAssets(fetchOption).then((albumFetchResult) => { console.info('album getAssets successfully, getCount: ' + albumFetchResult.getCount()); }).catch((err: BusinessError) => { console.error(`album getAssets failed with error: ${err.code}, ${err.message}`); }); } ``` ### commitModify commitModify(callback: AsyncCallback<void>): void Commits the modification on the album attributes to the database. This API uses an asynchronous callback to return the result. **Required permissions**: ohos.permission.WRITE_IMAGEVIDEO **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | ---------- | | callback | AsyncCallback<void> | Yes | Callback that returns no value.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example() { console.info('albumCommitModifyDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let albumFetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let albumList: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, albumFetchOptions); let album: photoAccessHelper.Album = await albumList.getFirstObject(); album.albumName = 'hello'; album.commitModify((err) => { if (err !== undefined) { console.error(`commitModify failed with error: ${err.code}, ${err.message}`); } else { console.info('commitModify successfully'); } }); } ``` ### commitModify commitModify(): Promise<void> Commits the modification on the album attributes to the database. This API uses a promise to return the result. **Required permissions**: ohos.permission.WRITE_IMAGEVIDEO **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Return value** | Type | Description | | ------------------- | ------------ | | Promise<void> | Promise that returns no value.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; import { BusinessError } from '@kit.BasicServicesKit'; async function example() { console.info('albumCommitModifyDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let albumFetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let albumList: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, albumFetchOptions); let album: photoAccessHelper.Album = await albumList.getFirstObject(); album.albumName = 'hello'; album.commitModify().then(() => { console.info('commitModify successfully'); }).catch((err: BusinessError) => { console.error(`commitModify failed with error: ${err.code}, ${err.message}`); }); } ``` ### addAssets(deprecated) addAssets(assets: Array<PhotoAsset>, callback: AsyncCallback<void>): void Adds image and video assets to an album. Before the operation, ensure that the image and video assets to add and the album exist. This API uses an asynchronous callback to return the result. > **NOTE** > > This API is supported since API version 10 and deprecated since API version 11. Use [MediaAlbumChangeRequest.addAssets](#addassets11) instead. **Required permissions**: ohos.permission.WRITE_IMAGEVIDEO **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | ---------- | | assets | Array<[PhotoAsset](#photoasset)> | Yes | Array of the image and video assets to add.| | callback | AsyncCallback<void> | Yes | Callback that returns no value.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example() { try { console.info('addAssetsDemoCallback'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let albumFetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); album.addAssets([asset], (err) => { if (err === undefined) { console.info('album addAssets successfully'); } else { console.error(`album addAssets failed with error: ${err.code}, ${err.message}`); } }); } catch (err) { console.error(`addAssetsDemoCallback failed with error: ${err.code}, ${err.message}`); } } ``` ### addAssets(deprecated) addAssets(assets: Array<PhotoAsset>): Promise<void> Adds image and video assets to an album. Before the operation, ensure that the image and video assets to add and the album exist. This API uses a promise to return the result. > **NOTE** > > This API is supported since API version 10 and deprecated since API version 11. Use [MediaAlbumChangeRequest.addAssets](#addassets11) instead. **Required permissions**: ohos.permission.WRITE_IMAGEVIDEO **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | ---------- | | assets | Array<[PhotoAsset](#photoasset)> | Yes | Array of the image and video assets to add.| **Return value** | Type | Description | | --------------------------------------- | ----------------- | |Promise<void> | Promise that returns no value.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; import { BusinessError } from '@kit.BasicServicesKit'; async function example() { try { console.info('addAssetsDemoPromise'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let albumFetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); album.addAssets([asset]).then(() => { console.info('album addAssets successfully'); }).catch((err: BusinessError) => { console.error(`album addAssets failed with error: ${err.code}, ${err.message}`); }); } catch (err) { console.error(`addAssetsDemoPromise failed with error: ${err.code}, ${err.message}`); } } ``` ### removeAssets(deprecated) removeAssets(assets: Array<PhotoAsset>, callback: AsyncCallback<void>): void Removes image and video assets from an album. The album and file resources must exist. This API uses an asynchronous callback to return the result. > **NOTE** > > This API is supported since API version 10 and deprecated since API version 11. Use [MediaAlbumChangeRequest.removeAssets](#removeassets11) instead. **Required permissions**: ohos.permission.WRITE_IMAGEVIDEO **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | ---------- | | assets | Array<[PhotoAsset](#photoasset)> | Yes | Array of the image and video assets to remove.| | callback | AsyncCallback<void> | Yes | Callback that returns no value.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example() { try { console.info('removeAssetsDemoCallback'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let albumFetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); let fetchResult: photoAccessHelper.FetchResult = await album.getAssets(fetchOption); let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); album.removeAssets([asset], (err) => { if (err === undefined) { console.info('album removeAssets successfully'); } else { console.error(`album removeAssets failed with error: ${err.code}, ${err.message}`); } }); } catch (err) { console.error(`removeAssetsDemoCallback failed with error: ${err.code}, ${err.message}`); } } ``` ### removeAssets(deprecated) removeAssets(assets: Array<PhotoAsset>): Promise<void> Removes image and video assets from an album. The album and file resources must exist. This API uses a promise to return the result. > **NOTE** > > This API is supported since API version 10 and deprecated since API version 11. Use [MediaAlbumChangeRequest.removeAssets](#removeassets11) instead. **Required permissions**: ohos.permission.WRITE_IMAGEVIDEO **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | ---------- | | assets | Array<[PhotoAsset](#photoasset)> | Yes | Array of the image and video assets to remove.| **Return value** | Type | Description | | --------------------------------------- | ----------------- | |Promise<void> | Promise that returns no value.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; import { BusinessError } from '@kit.BasicServicesKit'; async function example() { try { console.info('removeAssetsDemoPromise'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let albumFetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); let fetchResult: photoAccessHelper.FetchResult = await album.getAssets(fetchOption); let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); album.removeAssets([asset]).then(() => { console.info('album removeAssets successfully'); }).catch((err: BusinessError) => { console.error(`album removeAssets failed with error: ${err.code}, ${err.message}`); }); } catch (err) { console.error(`removeAssetsDemoPromise failed with error: ${err.code}, ${err.message}`); } } ``` ## MediaAssetChangeRequest11+ Represents a media asset change request. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core ### constructor11+ constructor(asset: PhotoAsset) Constructor. **Atomic service API**: This API can be used in atomic services since API version 12. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | ---------- | | asset | [PhotoAsset](#photoasset) | Yes | Assets to change.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example() { console.info('MediaAssetChangeRequest constructorDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(photoAsset); } ``` ### createImageAssetRequest11+ static createImageAssetRequest(context: Context, fileUri: string): MediaAssetChangeRequest Creates an image asset change request. Use **fileUri** to specify the data source of the asset to be created. For details, see [FileUri](../apis-core-file-kit/js-apis-file-fileuri.md). **Atomic service API**: This API can be used in atomic services since API version 12. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory| Description | | ------- | ------- | ---- | -------------------------- | | context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.| | fileUri | string | Yes | Data source of the image asset, which is specified by a URI in the application sandbox directory.| **Return value** | Type | Description | | --------------------------------------- | ----------------- | | [MediaAssetChangeRequest](#mediaassetchangerequest11) | **MediaAssetChangeRequest** created.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900002 | No such file. | | 14000011 | System inner fail. | **Example** ```ts async function example() { console.info('createImageAssetRequestDemo'); try { // Ensure that the asset specified by fileUri exists. let fileUri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/test.jpg'; let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = photoAccessHelper.MediaAssetChangeRequest.createImageAssetRequest(context, fileUri); await phAccessHelper.applyChanges(assetChangeRequest); console.info('apply createImageAssetRequest successfully'); } catch (err) { console.error(`createImageAssetRequestDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### createVideoAssetRequest11+ static createVideoAssetRequest(context: Context, fileUri: string): MediaAssetChangeRequest Creates a video asset change request. Use **fileUri** to specify the data source of the asset to be created. For details, see [FileUri](../apis-core-file-kit/js-apis-file-fileuri.md). **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory| Description | | ------- | ------- | ---- | -------------------------- | | context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.| | fileUri | string | Yes | Data source of the video asset, which is specified by a URI in the application sandbox directory.| **Return value** | Type | Description | | --------------------------------------- | ----------------- | | [MediaAssetChangeRequest](#mediaassetchangerequest11) | **MediaAssetChangeRequest** created.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900002 | No such file. | | 14000011 | System inner fail. | **Example** ```ts async function example() { console.info('createVideoAssetRequestDemo'); try { // Ensure that the asset specified by fileUri exists. let fileUri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/test.mp4'; let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = photoAccessHelper.MediaAssetChangeRequest.createVideoAssetRequest(context, fileUri); await phAccessHelper.applyChanges(assetChangeRequest); console.info('apply createVideoAssetRequest successfully'); } catch (err) { console.error(`createVideoAssetRequestDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### createAssetRequest11+ static createAssetRequest(context: Context, photoType: PhotoType, extension: string, options?: CreateOptions): MediaAssetChangeRequest Create an asset change request based on the file type and filename extension. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory| Description | | ------- | ------- | ---- | -------------------------- | | context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.| | photoType | [PhotoType](#phototype) | Yes | Type of the file to create, which can be **IMAGE** or **VIDEO**. | | extension | string | Yes | File name extension, for example, **'jpg'**. | | options | [CreateOptions](#createoptions) | No | Options for creating the image or video asset, for example, **{title: 'testPhoto'}**. | **Return value** | Type | Description | | --------------------------------------- | ----------------- | | [MediaAssetChangeRequest](#mediaassetchangerequest11) | **MediaAssetChangeRequest** created.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | **Example** ```ts async function example() { console.info('createAssetRequestDemo'); try { let photoType: photoAccessHelper.PhotoType = photoAccessHelper.PhotoType.IMAGE; let extension: string = 'jpg'; let options: photoAccessHelper.CreateOptions = { title: 'testPhoto' } let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = photoAccessHelper.MediaAssetChangeRequest.createAssetRequest(context, photoType, extension, options); // Ensure that the asset specified by fileUri exists. let fileUri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/test.jpg'; assetChangeRequest.addResource(photoAccessHelper.ResourceType.IMAGE_RESOURCE, fileUri); await phAccessHelper.applyChanges(assetChangeRequest); console.info('apply createAssetRequest successfully'); } catch (err) { console.error(`createAssetRequestDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### deleteAssets11+ static deleteAssets(context: Context, assets: Array<PhotoAsset>): Promise<void> Deletes media assets. This API uses a promise to return the result. The deleted assets are moved to the trash. **Required permissions**: ohos.permission.WRITE_IMAGEVIDEO **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory| Description | | ------- | ------- | ---- | -------------------------- | | context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.| | assets | Array<[PhotoAsset](#photoasset)> | Yes | Media assets to delete.| **Return value** | Type | Description | | --------------------------------------- | ----------------- | | Promise<void>| Promise that returns no value.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 201 | Permission denied. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example() { console.info('deleteAssetsDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; try { let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); let photoAssetList: Array = await fetchResult.getAllObjects(); await photoAccessHelper.MediaAssetChangeRequest.deleteAssets(context, photoAssetList); console.info('deleteAssets successfully'); } catch (err) { console.error(`deleteAssetsDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### deleteAssets11+ static deleteAssets(context: Context, uriList: Array<string>): Promise<void> Deletes media assets. This API uses a promise to return the result. The deleted assets are moved to the trash. **Required permissions**: ohos.permission.WRITE_IMAGEVIDEO **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory| Description | | ------- | ------- | ---- | -------------------------- | | context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.| | uriList | Array<string> | Yes | URIs of the media files to delete.| **Return value** | Type | Description | | --------------------------------------- | ----------------- | | Promise<void>| Promise that returns no value.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 201 | Permission denied. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000002 | Invalid asset uri. | | 14000011 | System inner fail. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example() { console.info('deleteAssetsDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; try { let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); await photoAccessHelper.MediaAssetChangeRequest.deleteAssets(context, [asset.uri]); console.info('deleteAssets successfully'); } catch (err) { console.error(`deleteAssetsDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### getAsset11+ getAsset(): PhotoAsset Obtains the asset in this asset change request. > **NOTE**
For the change request used to create an asset, this API returns **null** before [applyChanges](#applychanges11) is called to apply the changes. **Atomic service API**: This API can be used in atomic services since API version 12. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Return value** | Type | Description | | --------------------------------------- | ----------------- | | [PhotoAsset](#photoasset) | Asset obtained.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 14000011 | System inner fail. | **Example** ```ts async function example() { console.info('getAssetDemo'); try { // Ensure that the asset specified by fileUri exists. let fileUri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/test.jpg'; let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = photoAccessHelper.MediaAssetChangeRequest.createImageAssetRequest(context, fileUri); await phAccessHelper.applyChanges(assetChangeRequest); let asset: photoAccessHelper.PhotoAsset = assetChangeRequest.getAsset(); console.info('create asset successfully with uri = ' + asset.uri); } catch (err) { console.error(`getAssetDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### setTitle11+ setTitle(title: string): void Sets the media asset title. **Atomic service API**: This API can be used in atomic services since API version 12. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory | Description | | ---------- | ------- | ---- | ---------------------------------- | | title | string | Yes | Title to set.| The title must meet the following requirements: - It does not contain a file name extension. - The file name cannot exceed 255 characters. - It does not contain any of the following characters:
. \ / : * ? " ' ` < > | { } [ ] **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; import { BusinessError } from '@kit.BasicServicesKit'; async function example() { console.info('setTitleDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); let asset = await fetchResult.getFirstObject(); let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); let newTitle: string = 'newTitle'; assetChangeRequest.setTitle(newTitle); phAccessHelper.applyChanges(assetChangeRequest).then(() => { console.info('apply setTitle successfully'); }).catch((err: BusinessError) => { console.error(`apply setTitle failed with error: ${err.code}, ${err.message}`); }); } ``` ### getWriteCacheHandler11+ getWriteCacheHandler(): Promise<number> Obtains the handler used for writing a file to cache. > **NOTE**
For the same asset change request, this API cannot be repeatedly called after a temporary file write handle is successfully obtained. **Required permissions**: ohos.permission.WRITE_IMAGEVIDEO **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Return value** | Type | Description | | --------------------------------------- | ----------------- | | Promise<number> | Promise used to return the write handle obtained.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 201 | Permission denied. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 14000011 | System inner fail. | | 14000016 | Operation Not Support. | **Example** ```ts import { fileIo } from '@kit.CoreFileKit'; async function example() { console.info('getWriteCacheHandlerDemo'); try { let photoType: photoAccessHelper.PhotoType = photoAccessHelper.PhotoType.VIDEO; let extension: string = 'mp4'; let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = photoAccessHelper.MediaAssetChangeRequest.createAssetRequest(context, photoType, extension); let fd: number = await assetChangeRequest.getWriteCacheHandler(); console.info('getWriteCacheHandler successfully'); // write date into fd await fileIo.close(fd); await phAccessHelper.applyChanges(assetChangeRequest); } catch (err) { console.error(`getWriteCacheHandlerDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### addResource11+ addResource(type: ResourceType, fileUri: string): void Adds a resource using **fileUri**. > **NOTE**
For the same asset change request, this API cannot be repeatedly called after the resource is successfully added. For a moving photo, you can call this API twice to add the image and video resources. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory| Description | | ------- | ------- | ---- | -------------------------- | | type | [ResourceType](#resourcetype11) | Yes | Type of the resource to add.| | fileUri | string | Yes | Data source of the resource to be added, which is specified by a URI in the application sandbox directory.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900002 | No such file. | | 14000011 | System inner fail. | | 14000016 | Operation Not Support. | **Example** ```ts async function example() { console.info('addResourceByFileUriDemo'); try { let photoType: photoAccessHelper.PhotoType = photoAccessHelper.PhotoType.IMAGE; let extension: string = 'jpg'; let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = photoAccessHelper.MediaAssetChangeRequest.createAssetRequest(context, photoType, extension); // Ensure that the asset specified by fileUri exists. let fileUri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/test.jpg'; assetChangeRequest.addResource(photoAccessHelper.ResourceType.IMAGE_RESOURCE, fileUri); await phAccessHelper.applyChanges(assetChangeRequest); console.info('addResourceByFileUri successfully'); } catch (err) { console.error(`addResourceByFileUriDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### addResource11+ addResource(type: ResourceType, data: ArrayBuffer): void Adds a resource using **ArrayBuffer** data. > **NOTE**
For the same asset change request, this API cannot be repeatedly called after the resource is successfully added. For a moving photo, you can call this API twice to add the image and video resources. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory| Description | | ------- | ------- | ---- | -------------------------- | | type | [ResourceType](#resourcetype11) | Yes | Type of the resource to add.| | data | ArrayBuffer | Yes | Data of the resource to add.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | | 14000016 | Operation Not Support. | **Example** ```ts async function example() { console.info('addResourceByArrayBufferDemo'); try { let photoType: photoAccessHelper.PhotoType = photoAccessHelper.PhotoType.IMAGE; let extension: string = 'jpg'; let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = photoAccessHelper.MediaAssetChangeRequest.createAssetRequest(context, photoType, extension); let buffer: ArrayBuffer = new ArrayBuffer(2048); assetChangeRequest.addResource(photoAccessHelper.ResourceType.IMAGE_RESOURCE, buffer); await phAccessHelper.applyChanges(assetChangeRequest); console.info('addResourceByArrayBuffer successfully'); } catch (err) { console.error(`addResourceByArrayBufferDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### saveCameraPhoto12+ saveCameraPhoto(): void Saves the photo taken by the camera. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Error codes** For details about the error codes, see [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 14000011 | System inner fail. | | 14000016 | Operation Not Support. | **Example** ```ts async function example(asset: photoAccessHelper.PhotoAsset) { console.info('saveCameraPhotoDemo'); try { let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); assetChangeRequest.saveCameraPhoto(); await phAccessHelper.applyChanges(assetChangeRequest); console.info('apply saveCameraPhoto successfully'); } catch (err) { console.error(`apply saveCameraPhoto failed with error: ${err.code}, ${err.message}`); } } ``` ### saveCameraPhoto13+ saveCameraPhoto(imageFileType: ImageFileType): void Saves the photo taken by the camera. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | ---------- | | imageFileType | [ImageFileType](#imagefiletype13) | Yes | File type of the photo to save.| **Error codes** For details about the error codes, see [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 14000011 | System inner fail. | | 14000016 | Operation Not Support. | **Example** ```ts import { photoAccessHelper } from '@kit.MediaLibraryKit'; import { dataSharePredicates } from '@kit.ArkData'; import { image } from '@kit.ImageKit'; async function example(asset: photoAccessHelper.PhotoAsset) { console.info('saveCameraPhotoDemo'); try { let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); assetChangeRequest.saveCameraPhoto(photoAccessHelper.ImageFileType.JPEG); await phAccessHelper.applyChanges(assetChangeRequest); console.info('apply saveCameraPhoto successfully'); } catch (err) { console.error(`apply saveCameraPhoto failed with error: ${err.code}, ${err.message}`); } } ``` ### discardCameraPhoto12+ discardCameraPhoto(): void Discards the photo taken by the camera. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Error codes** For details about the error codes, see [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 14000011 | Internal system error. | | 14000016 | Operation Not Support. | **Example** ```ts async function example(asset: photoAccessHelper.PhotoAsset) { console.info('discardCameraPhotoDemo'); try { let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); assetChangeRequest.discardCameraPhoto(); await phAccessHelper.applyChanges(assetChangeRequest); console.info('apply discardCameraPhoto successfully'); } catch (err) { console.error(`apply discardCameraPhoto failed with error: ${err.code}, ${err.message}`); } } ``` ## MediaAlbumChangeRequest11+ Provides APIs for managing the media album change request. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core ### constructor11+ constructor(album: Album) Constructor. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | ---------- | | album | [Album](#album) | Yes | Album to change.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example() { console.info('MediaAlbumChangeRequest constructorDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, fetchOptions); let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); } ``` ### getAlbum11+ getAlbum(): Album Obtains the album in the current album change request. > **NOTE**
For the change request for creating an album, this API returns **null** before [applyChanges](#applychanges11) is called to apply the changes. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Return value** | Type | Description | | --------------------------------------- | ----------------- | | [Album](#album) | Album obtained.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 14000011 | System inner fail. | **Example** ```ts async function example() { console.info('getAlbumDemo'); try { // Ensure that the user album exists in the gallery. let albumFetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); let changeRequestAlbum: photoAccessHelper.Album = albumChangeRequest.getAlbum(); console.info('change request album uri: ' + changeRequestAlbum.albumUri); } catch (err) { console.error(`getAlbumDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### setAlbumName11+ setAlbumName(name: string): void Sets the album name. The album name must comply with the following specifications: - It does not exceed 255 characters. - It does not contain any of the following characters:
. \ / : * ? " ' ` < > | { } [ ] - It is case-insensitive. - Duplicate album names are not allowed. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory | Description | | ---------- | ------- | ---- | ---------------------------------- | | name | string | Yes | Album name to set.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | **Example** ```ts async function example() { console.info('setAlbumNameDemo'); try { let albumFetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); let newAlbumName: string = 'newAlbumName' + new Date().getTime(); albumChangeRequest.setAlbumName(newAlbumName); await phAccessHelper.applyChanges(albumChangeRequest); console.info('setAlbumName successfully'); } catch (err) { console.error(`setAlbumNameDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### addAssets11+ addAssets(assets: Array<PhotoAsset>): void Add assets to the album. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory | Description | | ---------- | ------- | ---- | ---------------------------------- | | assets | Array<[PhotoAsset](#photoasset)> | Yes | Assets to add.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | | 14000016 | Operation Not Support. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example() { console.info('addAssetsDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; try { // Ensure that user albums and photos exist in Gallery. let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); let albumFetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); albumChangeRequest.addAssets([asset]); await phAccessHelper.applyChanges(albumChangeRequest); console.info('addAssets successfully'); } catch (err) { console.error(`addAssetsDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### removeAssets11+ removeAssets(assets: Array<PhotoAsset>): void Removes assets from the album. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory | Description | | ---------- | ------- | ---- | ---------------------------------- | | assets | Array<[PhotoAsset](#photoasset)> | Yes | Assets to remove.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | | 14000016 | Operation Not Support. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example() { console.info('removeAssetsDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; try { let albumFetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); let fetchResult: photoAccessHelper.FetchResult = await album.getAssets(fetchOptions); let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); albumChangeRequest.removeAssets([asset]); await phAccessHelper.applyChanges(albumChangeRequest); console.info('removeAssets successfully'); } catch (err) { console.error(`removeAssetsDemo failed with error: ${err.code}, ${err.message}`); } } ``` ## MediaAssetManager11+ A media asset manager class, used for manipulating the read and write operations of media assets. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core ### requestImage11+ static requestImage(context: Context, asset: PhotoAsset, requestOptions: RequestOptions, dataHandler: MediaAssetDataHandler<image.ImageSource>): Promise<string> Requests an image. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Required permissions**: ohos.permission.READ_IMAGEVIDEO - If the caller does not have the ohos.permission.READ_IMAGEVIDEO permission, use Picker to access the file and then call this API based on the URI obtained by Picker. For details, see [Obtaining an Image or Video by URI](../../media/medialibrary/photoAccessHelper-photoviewpicker.md#obtaining-an-image-or-video-by-uri). - For the media assets saved to the media library by this application, the application can access them without the ohos.permission.READ_IMAGEVIDEO permission. **Parameters** | Name | Type | Mandatory| Description | |----------------|-----------------------------------------------------------------------------------------------------------| ---- | ------------------------- | | context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.| | asset | [PhotoAsset](#photoasset) | Yes | Image to request.| | requestOptions | [RequestOptions](#requestoptions11) | Yes | Options for requesting the image.| | dataHandler | [MediaAssetDataHandler](#mediaassetdatahandler11)<[image.ImageSource](../apis-image-kit/js-apis-image.md#imagesource)> | Yes | Media asset handler, which invokes a callback to return the image when the requested image is ready.| **Return value** | Type | Description | | --------------------------------------- | ----------------- | | Promise\ | Promise used to return the request ID, which can be used in [cancelRequest](#cancelrequest12) to cancel a request.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 201 | Permission denied | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; import { image } from '@kit.ImageKit'; class MediaHandler implements photoAccessHelper.MediaAssetDataHandler { onDataPrepared(data: image.ImageSource) { if (data === undefined) { console.error('Error occurred when preparing data'); return; } console.info('on image data prepared'); } } async function example() { console.info('requestImage'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let requestOptions: photoAccessHelper.RequestOptions = { deliveryMode: photoAccessHelper.DeliveryMode.HIGH_QUALITY_MODE, } const handler = new MediaHandler(); phAccessHelper.getAssets(fetchOptions, async (err, fetchResult) => { console.info('fetchResult success'); let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); await photoAccessHelper.MediaAssetManager.requestImage(context, photoAsset, requestOptions, handler); console.info('requestImage successfully'); }); } ``` ### requestImageData11+ static requestImageData(context: Context, asset: PhotoAsset, requestOptions: RequestOptions, dataHandler: MediaAssetDataHandler<ArrayBuffer>): Promise<string> Requests an image. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Required permissions**: ohos.permission.READ_IMAGEVIDEO - If the caller does not have the ohos.permission.READ_IMAGEVIDEO permission, use Picker to access the file and then call this API based on the URI obtained by Picker. For details, see [Obtaining an Image or Video by URI](../../media/medialibrary/photoAccessHelper-photoviewpicker.md#obtaining-an-image-or-video-by-uri). - For the media assets saved to the media library by this application, the application can access them without the ohos.permission.READ_IMAGEVIDEO permission. **Parameters** | Name | Type | Mandatory| Description | | -------- |----------------------------------------------------------------------| ---- | ------------------------- | | context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.| | asset | [PhotoAsset](#photoasset) | Yes | Image to request.| | requestOptions | [RequestOptions](#requestoptions11) | Yes | Options for requesting the image.| | dataHandler | [MediaAssetDataHandler](#mediaassetdatahandler11)<ArrayBuffer> | Yes | Media asset handler, which invokes a callback to return the image when the requested image is ready.| **Return value** | Type | Description | | --------------------------------------- | ----------------- | | Promise\ | Promise used to return the request ID, which can be used in [cancelRequest](#cancelrequest12) to cancel a request.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 201 | Permission denied | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; class MediaDataHandler implements photoAccessHelper.MediaAssetDataHandler { onDataPrepared(data: ArrayBuffer) { if (data === undefined) { console.error('Error occurred when preparing data'); return; } console.info('on image data prepared'); } } async function example() { console.info('requestImageData'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let requestOptions: photoAccessHelper.RequestOptions = { deliveryMode: photoAccessHelper.DeliveryMode.HIGH_QUALITY_MODE, } const handler = new MediaDataHandler(); phAccessHelper.getAssets(fetchOptions, async (err, fetchResult) => { console.info('fetchResult success'); let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); await photoAccessHelper.MediaAssetManager.requestImageData(context, photoAsset, requestOptions, handler); console.info('requestImageData successfully'); }); } ``` ### requestMovingPhoto12+ static requestMovingPhoto(context: Context, asset: PhotoAsset, requestOptions: RequestOptions, dataHandler: MediaAssetDataHandler<MovingPhoto>): Promise<string> Requests a moving photo object, which can be used to request the asset data of the moving photo. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Required permissions**: ohos.permission.READ_IMAGEVIDEO - If the caller does not have the ohos.permission.READ_IMAGEVIDEO permission, use Picker to access the file and then call this API based on the URI obtained by Picker. For details, see [Obtaining an Image or Video by URI](../../media/medialibrary/photoAccessHelper-photoviewpicker.md#obtaining-an-image-or-video-by-uri). - For the moving photos saved to the media library by this application, the application can access them without the ohos.permission.READ_IMAGEVIDEO permission. **Parameters** | Name | Type | Mandatory| Description | | -------- |----------------------------------------------------------------------| ---- | ------------------------- | | context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.| | asset | [PhotoAsset](#photoasset) | Yes | Image to request.| | requestOptions | [RequestOptions](#requestoptions11) | Yes | Options for requesting the image.| | dataHandler | [MediaAssetDataHandler](#mediaassetdatahandler11)<[MovingPhoto](#movingphoto12)> | Yes | Media asset handler, which invokes a callback to return the image when the requested image is ready.| **Return value** | Type | Description | | --------------------------------------- | ----------------- | | Promise\ | Promise used to return the request ID, which can be used in [cancelRequest](#cancelrequest12) to cancel a request.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 201 | Permission denied | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; class MovingPhotoHandler implements photoAccessHelper.MediaAssetDataHandler { async onDataPrepared(movingPhoto: photoAccessHelper.MovingPhoto) { if (movingPhoto === undefined) { console.error('Error occurred when preparing data'); return; } console.info("moving photo acquired successfully, uri: " + movingPhoto.getUri()); } } async function example() { let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); predicates.equalTo(photoAccessHelper.PhotoKeys.PHOTO_SUBTYPE, photoAccessHelper.PhotoSubtype.MOVING_PHOTO); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; // Ensure that there are moving photos in Gallery. let assetResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); let asset: photoAccessHelper.PhotoAsset = await assetResult.getFirstObject(); let requestOptions: photoAccessHelper.RequestOptions = { deliveryMode: photoAccessHelper.DeliveryMode.FAST_MODE, } const handler = new MovingPhotoHandler(); try { let requestId: string = await photoAccessHelper.MediaAssetManager.requestMovingPhoto(context, asset, requestOptions, handler); console.info("moving photo requested successfully, requestId: " + requestId); } catch (err) { console.error(`failed to request moving photo, error code is ${err.code}, message is ${err.message}`); } } ``` ### requestVideoFile12+ static requestVideoFile(context: Context, asset: PhotoAsset, requestOptions: RequestOptions, fileUri: string, dataHandler: MediaAssetDataHandler<boolean>): Promise<string> Requests a video and saves it to the specified sandbox directory. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Required permissions**: ohos.permission.READ_IMAGEVIDEO - If the caller does not have the ohos.permission.READ_IMAGEVIDEO permission, use Picker to access the file and then call this API based on the URI obtained by Picker. For details, see [Obtaining an Image or Video by URI](../../media/medialibrary/photoAccessHelper-photoviewpicker.md#obtaining-an-image-or-video-by-uri). - For the videos saved to the media library by this application, the application can access them without the ohos.permission.READ_IMAGEVIDEO permission. **Parameters** | Name | Type | Mandatory| Description | | -------- |----------------------------------------------------------------------| ---- | ------------------------- | | context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.| | asset | [PhotoAsset](#photoasset) | Yes | Image to request.| | requestOptions | [RequestOptions](#requestoptions11) | Yes | Options for requesting the video asset.| | fileUri| string | Yes| URI of the sandbox directory, to which the requested video asset is to be saved.| | dataHandler | [MediaAssetDataHandler](#mediaassetdatahandler11)<boolean> | Yes | Media asset handler. When the requested video is written to the specified directory, a callback is triggered.| **Return value** | Type | Description | | --------------------------------------- | ----------------- | | Promise\ | Promise used to return the request ID, which can be used in [cancelRequest](#cancelrequest12) to cancel a request.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 201 | Permission denied | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; class MediaDataHandler implements photoAccessHelper.MediaAssetDataHandler { onDataPrepared(data: boolean) { console.info('on video request status prepared'); } } async function example() { console.info('requestVideoFile'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let requestOptions: photoAccessHelper.RequestOptions = { deliveryMode: photoAccessHelper.DeliveryMode.HIGH_QUALITY_MODE, } const handler = new MediaDataHandler(); let fileUri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/test.mp4'; phAccessHelper.getAssets(fetchOptions, async (err, fetchResult) => { console.info('fetchResult success'); let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); await photoAccessHelper.MediaAssetManager.requestVideoFile(context, photoAsset, requestOptions, fileUri, handler); console.info('requestVideoFile successfully'); }); } ``` ### cancelRequest12+ static cancelRequest(context: Context, requestId: string): Promise\ Cancels a request for the asset, the callback of which has not been triggered yet. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Required permissions**: ohos.permission.READ_IMAGEVIDEO **Parameters** | Name | Type | Mandatory| Description | | -------- |----------------------------------------------------------------------| ---- | ------------------------- | | context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.| | requestId | string | Yes | ID of the request to cancel.| **Return value** | Type | Description | | --------------------------------------- | ----------------- | | Promise\ | Promise that returns no value.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 201 | Permission denied | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example() { try { let requestId: string = 'xxx-xxx'; // A valid requestId returned by APIs such as requestImage() must be used. await photoAccessHelper.MediaAssetManager.cancelRequest(context, requestId); console.info("request cancelled successfully"); } catch (err) { console.error(`cancelRequest failed with error: ${err.code}, ${err.message}`); } } ``` ### loadMovingPhoto12+ static loadMovingPhoto(context: Context, imageFileUri: string, videoFileUri: string): Promise\ Loads a moving photo in the application sandbox. **Atomic service API**: This API can be used in atomic services since API version 14. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory| Description | | -------- |----------------------------------------------------------------------| ---- | ------------------------- | | context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | **AbilityContext** or **UIExtensionContext** instance.| | imageFileUri | string | Yes | URI of the image file of the moving photo in the application sandbox.| | videoFileUri | string | Yes | URI of the video file of the moving photo in the application sandbox.| **Return value** | Type | Description | | --------------------------------------- | ----------------- | | Promise\ | Promise used to return a [MovingPhoto](#movingphoto12) instance.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | Internal system error. | **Example** ```ts async function example() { try { let imageFileUri: string = 'file://com.example.temptest/data/storage/el2/base/haps/ImageFile.jpg'; // URI of the image file of the moving photo in the application sandbox. let videoFileUri: string = 'file://com.example.temptest/data/storage/el2/base/haps/VideoFile.mp4'; // URI of the video file of the moving photo in the application sandbox. let movingPhoto: photoAccessHelper.MovingPhoto = await photoAccessHelper.MediaAssetManager.loadMovingPhoto(context, imageFileUri, videoFileUri); } catch (err) { console.error(`loadMovingPhoto failed with error: ${err.code}, ${err.message}`); } } ``` ### quickRequestImage13+ static quickRequestImage(context: Context, asset: PhotoAsset, requestOptions: RequestOptions, dataHandler: QuickImageDataHandler<image.Picture>): Promise<string> Requests an image quickly. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Required permissions**: ohos.permission.READ_IMAGEVIDEO If the caller does not have the ohos.permission.READ_IMAGEVIDEO permission, use Picker to access the file and then call this API based on the URI obtained by Picker. For details, see [Obtaining an Image or Video by URI](../../media/medialibrary/photoAccessHelper-photoviewpicker.md#obtaining-an-image-or-video-by-uri). **Parameters** | Name | Type | Mandatory| Description | |----------------|-----------------------------------------------------------------------------------------------------------| ---- | ------------------------- | | context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.| | asset | [PhotoAsset](#photoasset) | Yes | Image to request.| | requestOptions | [RequestOptions](#requestoptions11) | Yes | Options for requesting the image.| | dataHandler | [QuickImageDataHandler](#quickimagedatahandler13)<[image.Picture](../apis-image-kit/js-apis-image.md#picture13)> | Yes | Media asset handler, which invokes a callback to return the image when the requested image is ready.| **Return value** | Type | Description | | --------------------------------------- | ----------------- | | Promise\ | Promise used to return the request ID, which can be used in [cancelRequest](#cancelrequest12) to cancel a request.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 201 | Permission denied | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | Internal system error. | **Example** ```ts import { photoAccessHelper } from '@kit.MediaLibraryKit'; import { dataSharePredicates } from '@kit.ArkData'; import { image } from '@kit.ImageKit'; class MediaHandler implements photoAccessHelper.QuickImageDataHandler { onDataPrepared(data: image.Picture, imageSource: image.ImageSource, map: Map) { console.info('on image data prepared'); } } async function example() { console.info('quickRequestImage'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let requestOptions: photoAccessHelper.RequestOptions = { deliveryMode: photoAccessHelper.DeliveryMode.HIGH_QUALITY_MODE, } const handler = new MediaHandler(); let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); phAccessHelper.getAssets(fetchOptions, async (err, fetchResult) => { console.info('fetchResult success'); let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); await photoAccessHelper.MediaAssetManager.quickRequestImage(context, photoAsset, requestOptions, handler); console.info('quickRequestImage successfully'); }); } ``` ## MediaAssetDataHandler11+ Media asset handler, which can be used to customize the media asset processing logic in **onDataPrepared**. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core ### onDataPrepared11+ onDataPrepared(data: T, map?: Map): void Called 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. T supports the following data types: ArrayBuffer, [ImageSource](../apis-image-kit/js-apis-image.md#imagesource), [MovingPhoto](#movingphoto12), and boolean. ArrayBuffer indicates the image or video asset data, [ImageSource](../apis-image-kit/js-apis-image.md#imagesource) indicates the image source, [MovingPhoto](#movingphoto12) indicates a moving photo object, and boolean indicates whether the image or video is successfully written to the application sandbox directory. Information returned by **map**: | Map Key | **Description**| |----------|-------| | 'quality' | Image quality. The value **high** means high quality, and **low** means poor quality.| **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type| Mandatory| Description | |------|---| ---- |-------------------------------------------------------------------------------| | data | T | Yes | Data of the image asset that is ready. The value supports the following types: ArrayBuffer, [ImageSource](../apis-image-kit/js-apis-image.md#imagesource), [MovingPhoto](#movingphoto12), and boolean.| | map12+ | Map | No | Additional information about the image asset, such as the image quality.| **Example** ```ts import { image } from '@kit.ImageKit'; class MediaHandler implements photoAccessHelper.MediaAssetDataHandler { onDataPrepared(data: image.ImageSource, map: Map) { if (data === undefined) { console.error('Error occurred when preparing data'); return; } // Customize the processing logic for ImageSource. console.info('on image data prepared, photo quality is ' + map['quality']); } } class MediaDataHandler implements photoAccessHelper.MediaAssetDataHandler { onDataPrepared(data: ArrayBuffer, map: Map) { if (data === undefined) { console.error('Error occurred when preparing data'); return; } // Customize the processing logic for ArrayBuffer. console.info('on image data prepared, photo quality is ' + map['quality']); } } class MovingPhotoHandler implements photoAccessHelper.MediaAssetDataHandler { onDataPrepared(data: photoAccessHelper.MovingPhoto, map: Map) { if (data === undefined) { console.error('Error occurred when preparing data'); return; } // Customize the processing logic for MovingPhoto. console.info('on image data prepared, photo quality is ' + map['quality']); } } ``` ## QuickImageDataHandler13+ Media asset handler, which can be used to customize the media asset processing logic in **onDataPrepared**. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core ### onDataPrepared13+ onDataPrepared(data: T, imageSource: image.ImageSource, map: Map): void Called when the requested image is ready. If an error occurs, **data** returned by the callback is **undefined**. **T** supports the Picture data type. Information returned by **map**: | Map Key | **Description**| |----------|-------| | 'quality' | Image quality. The value **high** means high quality, and **low** means poor quality.| **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type| Mandatory| Description | |------|---| ---- |-------------------------------------------------------------------------------| | data | T | Yes | Data of the image asset that is ready. It is of the T type, which supports the [Picture](../apis-image-kit/js-apis-image.md#picture13) type.| | imageSource | image.ImageSource | Yes | Data of the image asset that is ready.| | map13+ | Map | Yes | Additional information about the image asset, such as the image quality.| **Example** ```ts import { image } from '@kit.ImageKit'; class MediaHandler implements photoAccessHelper.QuickImageDataHandler { onDataPrepared(data: image.Picture, imageSource: image.ImageSource, map: Map) { console.info('on image data prepared'); } } ``` ## MovingPhoto12+ Provides APIs for managing a moving photo instance. **Atomic service API**: This API can be used in atomic services since API version 12. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core ### getUri12+ getUri(): string Obtains the URI of this moving photo. **Atomic service API**: This API can be used in atomic services since API version 12. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Return value** | Type | Description | | --------------------------------------- | ----------------- | | string | URI of the moving photo obtained.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 14000011 | System inner fail. | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; class MovingPhotoHandler implements photoAccessHelper.MediaAssetDataHandler { async onDataPrepared(movingPhoto: photoAccessHelper.MovingPhoto) { if (movingPhoto === undefined) { console.error('Error occurred when preparing data'); return; } console.info("moving photo acquired successfully, uri: " + movingPhoto.getUri()); } } async function example() { let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); predicates.equalTo(photoAccessHelper.PhotoKeys.PHOTO_SUBTYPE, photoAccessHelper.PhotoSubtype.MOVING_PHOTO); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; // Ensure that there are moving photos in Gallery. let assetResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); let asset: photoAccessHelper.PhotoAsset = await assetResult.getFirstObject(); let requestOptions: photoAccessHelper.RequestOptions = { deliveryMode: photoAccessHelper.DeliveryMode.FAST_MODE, } const handler = new MovingPhotoHandler(); try { let requestId: string = await photoAccessHelper.MediaAssetManager.requestMovingPhoto(context, asset, requestOptions, handler); console.info("moving photo requested successfully, requestId: " + requestId); } catch (err) { console.error(`failed to request moving photo, error code is ${err.code}, message is ${err.message}`); } } ``` ### requestContent12+ requestContent(imageFileUri: string, videoFileUri: string): Promise\ Requests the image data and video data of this moving photo and writes them to the specified URIs, respectively. **Atomic service API**: This API can be used in atomic services since API version 12. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Required permissions**: ohos.permission.READ_IMAGEVIDEO - If the application does not have the ohos.permission.READ_IMAGEVIDEO permission, use Picker to call this API to request a moving photo object and read the content. For details, see [Accessing and Managing Moving Photos](../../media/medialibrary/photoAccessHelper-movingphoto.md). - For the moving photos saved to the media library by this application, the application can access them without the ohos.permission.READ_IMAGEVIDEO permission. **Parameters** | Name | Type | Mandatory| Description | | -------- |----------------------------------------------------------------------| ---- | ------------------------- | | imageFileUri | string | Yes | URI to which the image data of the moving photo is to be written.| | videoFileUri | string | Yes | URI to which the video data of the moving photo is to be written.| **Return value** | Type | Description | | --------------------------------------- | ----------------- | | Promise\ | Promise that returns no value.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 201 | Permission denied | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; class MovingPhotoHandler implements photoAccessHelper.MediaAssetDataHandler { async onDataPrepared(movingPhoto: photoAccessHelper.MovingPhoto) { if (movingPhoto === undefined) { console.error('Error occurred when preparing data'); return; } // The URIs must be valid. let imageFileUri: string = "file://com.example.temptest/data/storage/el2/base/haps/ImageFile.jpg"; let videoFileUri: string = "file://com.example.temptest/data/storage/el2/base/haps/VideoFile.mp4"; try { await movingPhoto.requestContent(imageFileUri, videoFileUri); console.log("moving photo contents retrieved successfully"); } catch (err) { console.error(`failed to retrieve contents of moving photo, error code is ${err.code}, message is ${err.message}`); } } } async function example() { let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); predicates.equalTo(photoAccessHelper.PhotoKeys.PHOTO_SUBTYPE, photoAccessHelper.PhotoSubtype.MOVING_PHOTO); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; // Ensure that there are moving photos in Gallery. let assetResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); let asset: photoAccessHelper.PhotoAsset = await assetResult.getFirstObject(); let requestOptions: photoAccessHelper.RequestOptions = { deliveryMode: photoAccessHelper.DeliveryMode.FAST_MODE, } const handler = new MovingPhotoHandler(); try { let requestId: string = await photoAccessHelper.MediaAssetManager.requestMovingPhoto(context, asset, requestOptions, handler); console.info("moving photo requested successfully, requestId: " + requestId); } catch (err) { console.error(`failed to request moving photo, error code is ${err.code}, message is ${err.message}`); } } ``` ### requestContent12+ requestContent(resourceType: ResourceType, fileUri: string): Promise\ Requests the moving photo content of the specified resource type and writes it to the specified URI. **Atomic service API**: This API can be used in atomic services since API version 12. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Required permissions**: ohos.permission.READ_IMAGEVIDEO - If the application does not have the ohos.permission.READ_IMAGEVIDEO permission, use Picker to call this API to request a moving photo object and read the content. For details, see [Accessing and Managing Moving Photos](../../media/medialibrary/photoAccessHelper-movingphoto.md). - For the moving photos saved to the media library by this application, the application can access them without the ohos.permission.READ_IMAGEVIDEO permission. **Parameters** | Name | Type | Mandatory| Description | | -------- |----------------------------------------------------------------------| ---- | ------------------------- | | resourceType | [ResourceType](#resourcetype11) | Yes | Resource type of the moving photo content to request.| | fileUri | string | Yes |URI to which the moving photo content is to be written.| **Return value** | Type | Description | | --------------------------------------- | ----------------- | | Promise\ | Promise that returns no value.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 201 | Permission denied | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; class MovingPhotoHandler implements photoAccessHelper.MediaAssetDataHandler { async onDataPrepared(movingPhoto: photoAccessHelper.MovingPhoto) { if (movingPhoto === undefined) { console.error('Error occurred when preparing data'); return; } // The URIs must be valid. let imageFileUri: string = "file://com.example.temptest/data/storage/el2/base/haps/ImageFile.jpg"; try { await movingPhoto.requestContent(photoAccessHelper.ResourceType.IMAGE_RESOURCE, imageFileUri); console.log("moving photo image content retrieved successfully"); } catch (err) { console.error(`failed to retrieve image content of moving photo, error code is ${err.code}, message is ${err.message}`); } } } async function example() { let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); predicates.equalTo(photoAccessHelper.PhotoKeys.PHOTO_SUBTYPE, photoAccessHelper.PhotoSubtype.MOVING_PHOTO); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; // Ensure that there are moving photos in Gallery. let assetResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); let asset: photoAccessHelper.PhotoAsset = await assetResult.getFirstObject(); let requestOptions: photoAccessHelper.RequestOptions = { deliveryMode: photoAccessHelper.DeliveryMode.FAST_MODE, } const handler = new MovingPhotoHandler(); try { let requestId: string = await photoAccessHelper.MediaAssetManager.requestMovingPhoto(context, asset, requestOptions, handler); console.info("moving photo requested successfully, requestId: " + requestId); } catch (err) { console.error(`failed to request moving photo, error code is ${err.code}, message is ${err.message}`); } } ``` ### requestContent12+ requestContent(resourceType: ResourceType): Promise\ Requests the moving photo content of the specified resource type and returns it in ArrayBuffer format. **Atomic service API**: This API can be used in atomic services since API version 12. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Required permissions**: ohos.permission.READ_IMAGEVIDEO - If the application does not have the ohos.permission.READ_IMAGEVIDEO permission, use Picker to call this API to request a moving photo object and read the content. For details, see [Accessing and Managing Moving Photos](../../media/medialibrary/photoAccessHelper-movingphoto.md). - For the moving photos saved to the media library by this application, the application can access them without the ohos.permission.READ_IMAGEVIDEO permission. **Parameters** | Name | Type | Mandatory| Description | | -------- |----------------------------------------------------------------------| ---- | ------------------------- | | resourceType | [ResourceType](#resourcetype11) | Yes | Resource type of the moving photo content to request.| **Return value** | Type | Description | | --------------------------------------- | ----------------- | | Promise\ | Promise used to return the requested content in an ArrayBuffer.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 201 | Permission denied | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail | **Example** ```ts import { dataSharePredicates } from '@kit.ArkData'; class MovingPhotoHandler implements photoAccessHelper.MediaAssetDataHandler { async onDataPrepared(movingPhoto: photoAccessHelper.MovingPhoto) { if (movingPhoto === undefined) { console.error('Error occurred when preparing data'); return; } try { let buffer: ArrayBuffer = await movingPhoto.requestContent(photoAccessHelper.ResourceType.IMAGE_RESOURCE); console.log("moving photo image content retrieved successfully, buffer length: " + buffer.byteLength); } catch (err) { console.error(`failed to retrieve image content of moving photo, error code is ${err.code}, message is ${err.message}`); } } } async function example() { let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); predicates.equalTo(photoAccessHelper.PhotoKeys.PHOTO_SUBTYPE, photoAccessHelper.PhotoSubtype.MOVING_PHOTO); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; // Ensure that there are moving photos in Gallery. let assetResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); let asset: photoAccessHelper.PhotoAsset = await assetResult.getFirstObject(); let requestOptions: photoAccessHelper.RequestOptions = { deliveryMode: photoAccessHelper.DeliveryMode.FAST_MODE, } const handler = new MovingPhotoHandler(); try { let requestId: string = await photoAccessHelper.MediaAssetManager.requestMovingPhoto(context, asset, requestOptions, handler); console.info("moving photo requested successfully, requestId: " + requestId); } catch (err) { console.error(`failed to request moving photo, error code is ${err.code}, message is ${err.message}`); } } ``` ## MemberType type MemberType = number | string | boolean Defines the types of the **PhotoAsset** members. The member types are the union of the types listed in the following table. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core | Type| Description| | ---- | ---- | | number | The member value is any number.| | string | The member value is any string.| | boolean | The member value is true or false.| ## PhotoType Enumerates media file types. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core | Name | Value| Description| | ----- | ---- | ---- | | IMAGE | 1 | Image.| | VIDEO | 2 | Video.| ## PhotoSubtype12+ Enumerates the [PhotoAsset](#photoasset) types. **Atomic service API**: This API can be used in atomic services since API version 12. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core | Name | Value| Description| | ----- | ---- | ---- | | DEFAULT | 0 | Photo, which is the default type.| | MOVING_PHOTO | 3 | Moving photo.| | BURST | 4 | Burst photo.| ## DynamicRangeType12+ Enumerates the formats for displaying media assets. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core | Name | Value| Description| | ----- | ---- | ---- | | SDR | 0 | Standard dynamic range (SDR).| | HDR | 1 | High dynamic range (HDR). | ## AlbumType Enumerates the album types. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core | Name | Value | Description | | ------------------- | ---- | ------------------------- | | USER | 0 | User album. | | SYSTEM | 1024 | System album. | ## AlbumSubtype Enumerate the album subtypes. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core | Name | Value | Description | | --------------------------------- | ---------- | ------------------------------- | | USER\_GENERIC | 1 | User album. | | FAVORITE | 1025 | Favorites. | | VIDEO | 1026 | Video album. | | IMAGE12+ | 1031 | Photo album. | | ANY | 2147483647 | Any album. | ## PhotoKeys Defines the key information about an image or video file. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core | Name | Value | Description | | ------------- | ------------------- | ---------------------------------------------------------- | | URI | 'uri' | URI of the file.
**NOTE**: Only the [DataSharePredicates.equalTo](../apis-arkdata/js-apis-data-dataSharePredicates.md#equalto10) predicate can be used for this field during photo query. | | PHOTO_TYPE | 'media_type' | Type of the file. | | DISPLAY_NAME | 'display_name' | File name displayed. | | SIZE | 'size' | File size, in bytes. | | DATE_ADDED | 'date_added' | Date when the file was added. The value is the number of seconds elapsed since the Epoch time (00:00:00 UTC on January 1, 1970). | | DATE_MODIFIED | 'date_modified' | Date when the file content (not the file name) was last modified. The value is the number of seconds elapsed since the Epoch time.| | DURATION | 'duration' | Duration, in ms. | | WIDTH | 'width' | Image width, in pixels. | | HEIGHT | 'height' | Image height, in pixels. | | DATE_TAKEN | 'date_taken' | Date when the file (photo) was taken. The value is the number of seconds elapsed since the Epoch time. | | ORIENTATION | 'orientation' | Orientation of the file, in degrees. | | FAVORITE | 'is_favorite' | Whether the file is added to favorites. | | TITLE | 'title' | Title in the file. | | DATE_ADDED_MS12+ | 'date_added_ms' | Date when the file was added. The value is the number of milliseconds elapsed since the Epoch time (00:00:00 UTC on January 1, 1970).
**NOTE**: The photos queried cannot be sorted based on this field. | | DATE_MODIFIED_MS12+ | 'date_modified_ms' | Date when the album file content (not the album name) was last modified. The value is the number of milliseconds elapsed since the Epoch time.
**NOTE**: The photos queried cannot be sorted based on this field.| | PHOTO_SUBTYPE12+ | 'subtype' | Subtype of the media file. | | DYNAMIC_RANGE_TYPE12+ | 'dynamic_range_type' | Dynamic range type of the media asset. | | COVER_POSITION12+ | 'cover_position' | Position of the moving photo cover, which is the video timestamp (in μs) corresponding to the cover frame.| | BURST_KEY12+ | 'burst_key' | Unique ID of a group of burst photos.| | LCD_SIZE12+ | 'lcd_size' | Width and height of an LCD image, in the format of a **width:height** string.| | THM_SIZE12+ | 'thm_size' | Width and height of a thumbnail image, in the format of a **width:height** string.| | DETAIL_TIME13+ | 'detail_time' | Detailed time. The value is a string of time when the image or video was taken in the time zone and does not change with the time zone.| | DATE_TAKEN_MS13+ | 'date_taken_ms' | Date when the image or video was taken. The value is the number of milliseconds elapsed since the Epoch time.| ## AlbumKeys Enumerates the key album attributes. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core | Name | Value | Description | | ------------- | ------------------- | ---------------------------------------------------------- | | URI | 'uri' | URI of the album. | | ALBUM_NAME | 'album_name' | Name of the album. | ## CreateOptions Options for creating an image or video asset. The title must meet the following requirements: - It does not contain a file name extension. - The file name cannot exceed 255 characters. - It does not contain any of the following characters:
. .. \ / : * ? " ' ` < > | { } [ ] **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core | Name | Type | Mandatory| Description | | ---------------------- | ------------------- | ---- | ------------------------------------------------ | | title | string | No | Title of the image or video. | | subtype12+ | [PhotoSubtype](#photosubtype12) | No | Subtype of the image or video file.
**Atomic service API**: This API can be used in atomic services since API version 12. | ## FetchOptions Defines the options for fetching media files. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core | Name | Type | Readable| Writable| Description | | ---------------------- | ------------------- | ---- |---- | ------------------------------------------------ | | fetchColumns | Array<string> | Yes | Yes | Names of the columns specified for query.
If this parameter is left blank for photos, photos are fetched by **'uri'**, **'media_type'**, **'subtype'**, and **'display_name'** by default. An error will be thrown if [get](#get) is used to obtain other attributes of this object.
Example: **fetchColumns: ['uri', 'title']**.
If this parameter is left blank for albums, albums are fetched by **'uri'** and **'album_name'** by default.| | predicates | [dataSharePredicates.DataSharePredicates](../apis-arkdata/js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes | Yes | Predicates that specify the fetch criteria.| ## RequestOptions11+ Represents request options. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core | Name | Type | Read-Only| Optional| Description | | ---------------------- |----------------------------| ---- | ---- | ------------------------------------------- | | deliveryMode | [DeliveryMode](#deliverymode11) | No | No | Delivery mode of the requested asset. The value can be **FAST_MODE**, **HIGH_QUALITY_MODE**, or **BALANCE_MODE**.| ## MediaChangeRequest11+ Media change request, which is the parent class of the asset change request and album change request. > **NOTE**
**MediaChangeRequest** takes effect only after [applyChanges](#applychanges11) is called. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core ## ResourceType11+ Enumerates the types of the resources to write. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core | Name | Value| Description| | ----- | ---- | ---- | | IMAGE_RESOURCE | 1 | Image resource.| | VIDEO_RESOURCE | 2 | Video resource.| ## ImageFileType13+ Enumerates the types of image files to save. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core | Name | Value| Description| | ----- | ---- | ---- | | JPEG | 1 | JPEG.| | HEIF | 2 | HEIF.| ## ChangeData Defines the return value of the listener callback. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core | Name | Type | Readable| Writable| Description | | ------- | --------------------------- | ---- | ---- | ------------------------------------------------------------ | | type | [NotifyType](#notifytype) | Yes | No | Notification type. | | uris | Array<string> | Yes | No | All URIs with the same [NotifyType](#notifytype), which can be **PhotoAsset** or **Album**.| | extraUris | Array<string> | Yes | No | URIs of the changed files in the album. | ## NotifyType Enumerates the notification event types. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core | Name | Value | Description | | ------------------------- | ---- | -------------------------------- | | NOTIFY_ADD | 0 | A file asset or album is added. | | NOTIFY_UPDATE | 1 | A file asset or album is updated. | | NOTIFY_REMOVE | 2 | A file asset or album is removed. | | NOTIFY_ALBUM_ADD_ASSET | 3 | A file asset is added to the album.| | NOTIFY_ALBUM_REMOVE_ASSET | 4 | A file asset is removed from the album.| ## DefaultChangeUri Enumerates the **DefaultChangeUri** subtypes. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core | Name | Value | Description | | ----------------- | ----------------------- | ------------------------------------------------------------ | | DEFAULT_PHOTO_URI | 'file://media/Photo' | Default **PhotoAsset** URI, which must be used with **forChildUris{true}** to subscribe to change notifications of all photo assets.| | DEFAULT_ALBUM_URI | 'file://media/PhotoAlbum' | Default album URI, which must be used with **forChildUris{true}** to subscribe to change notifications of all albums.| ## PhotoViewMIMETypes Enumerates the media file types that can be selected. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core | Name | Value| Description | |---------------------------------------| ---- |----------| | IMAGE_TYPE | 'image/*' | Image. | | VIDEO_TYPE | 'video/*' | Video. | | IMAGE_VIDEO_TYPE | '\*/*' | Image and video.| | MOVING_PHOTO_IMAGE_TYPE12+ | 'image/movingPhoto' | Moving photo.
**Atomic service API**: This API can be used in atomic services since API version 12. | ## RecommendationType11+ Enumerates the types of recommended images. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core | Name | Value| Description| | ----- | ---- | ---- | | QR_OR_BAR_CODE | 1 | QR code or barcode.| | QR_CODE | 2 | QR code.| | BAR_CODE | 3 | Barcode.| | ID_CARD | 4 | ID card.| | PROFILE_PICTURE | 5 | Profile.| | PASSPORT12+ | 6 | passport.
**Atomic service API**: This API can be used in atomic services since API version 12.| | BANK_CARD12+ | 7 | Bank card.
**Atomic service API**: This API can be used in atomic services since API version 12.| | DRIVER_LICENSE12+ | 8 | Driver license.
**Atomic service API**: This API can be used in atomic services since API version 12.| | DRIVING_LICENSE12+ | 9 | Vehicle license
**Atomic service API**: This API can be used in atomic services since API version 12.| | FEATURED_SINGLE_PORTRAIT12+ | 10 | Recommended portrait.
**Atomic service API**: This API can be used in atomic services since API version 12.| **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; async function example() { try { let recommendOptions: photoAccessHelper.RecommendationOptions = { recommendationType: photoAccessHelper.RecommendationType.ID_CARD } let options: photoAccessHelper.PhotoSelectOptions = { MIMEType: photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE, maxSelectNumber: 1, recommendationOptions: recommendOptions } let photoPicker = new photoAccessHelper.PhotoViewPicker(); photoPicker.select(options).then((PhotoSelectResult: photoAccessHelper.PhotoSelectResult) => { console.info('PhotoViewPicker.select successfully, PhotoSelectResult uri: ' + JSON.stringify(PhotoSelectResult)); }).catch((err: BusinessError) => { console.error(`PhotoViewPicker.select failed with err: ${err.code}, ${err.message}`); }); } catch (error) { let err: BusinessError = error as BusinessError; console.error(`PhotoViewPicker failed with err: ${err.code}, ${err.message}`); } } ``` ## TextContextInfo12+ Represents the text information about the recommended images. **Atomic service API**: This API can be used in atomic services since API version 12. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core | Name | Type | Mandatory| Description | | ----------------------- | ------------------- | ---- | -------------------------------- | | text | string | No | Text based on which images are recommended. The text cannot exceed 250 characters.| **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; async function example() { try { let textInfo: photoAccessHelper.TextContextInfo = { text: 'Pandas at Shanghai Wild Zoo' } let recommendOptions: photoAccessHelper.RecommendationOptions = { textContextInfo: textInfo } let options: photoAccessHelper.PhotoSelectOptions = { MIMEType: photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE, maxSelectNumber: 1, recommendationOptions: recommendOptions } let photoPicker = new photoAccessHelper.PhotoViewPicker(); photoPicker.select(options).then((PhotoSelectResult: photoAccessHelper.PhotoSelectResult) => { console.info('PhotoViewPicker.select successfully, PhotoSelectResult uri: ' + JSON.stringify(PhotoSelectResult)); }).catch((err: BusinessError) => { console.error(`PhotoViewPicker.select failed with err: ${err.code}, ${err.message}`); }); } catch (error) { let err: BusinessError = error as BusinessError; console.error(`PhotoViewPicker failed with err: ${err.code}, ${err.message}`); } } ``` ## RecommendationOptions11+ Defines the image recommendation options. The image recommendation feature depends on the image data analysis capability, which varies with devices. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core | Name | Type | Mandatory| Description | | ----------------------- | ------------------- | ---- | -------------------------------- | | recommendationType | [RecommendationType](#recommendationtype11) | No | Type of the recommended image.| | textContextInfo12+ | [TextContextInfo](#textcontextinfo12) | No | Text based on which images are recommended. If both **recommendationType** and **textContextInfo** are set, **textContextInfo** takes precedence over **recommendationType**.
**Atomic service API**: This API can be used in atomic services since API version 12.| ## BaseSelectOptions12+ Defines the basic options for selecting media assets from Gallery. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core | Name | Type | Mandatory| Description | | ----------------------- | ------------------- | ---- | -------------------------------- | | MIMEType10+ | [PhotoViewMIMETypes](#photoviewmimetypes) | No | Available media file types. **IMAGE_VIDEO_TYPE** is used by default.
**Atomic service API**: This API can be used in atomic services since API version 11.| | maxSelectNumber10+ | number | No | Maximum number of media files that can be selected.
Maximum value: **500**
Default value: **50**
**Atomic service API**: This API can be used in atomic services since API version 11. | | isPhotoTakingSupported11+ | boolean | No | Whether photo taking is supported.
The value **true** means photo taking is supported; the value **false** means the opposite.
**Atomic service API**: This API can be used in atomic services since API version 11.| | isSearchSupported11+ | boolean | No | Whether the image is searchable.
The value **true** means the image is searchable; the value **false** means the opposite.
**Atomic service API**: This API can be used in atomic services since API version 11.| | recommendationOptions11+ | [RecommendationOptions](#recommendationoptions11) | No | Image recommendation parameters.
**Atomic service API**: This API can be used in atomic services since API version 11.| | preselectedUris11+ | Array<string> | No | URI of the preselected image.
**Atomic service API**: This API can be used in atomic services since API version 11.| | isPreviewForSingleSelectionSupported12+ | boolean | No | Whether to enable full image preview if a single image is selected.
The value **true** means to enable full image preview; the value **false** means the opposite.
Default value: **true**
**Atomic service API**: This API can be used in atomic services since API version 12.| ## PhotoSelectOptions Defines additional options for selecting media assets from Gallery. It inherits from **BaseSelectOptions**. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core | Name | Type | Mandatory| Description | | ----------------------- | ------------------- | ---- | -------------------------------- | | isEditSupported11+ | boolean | No | Whether the image can be edited.
The value **true** means the image can be edited; the value **false** means the opposite. | | isOriginalSupported12+ | boolean | No | Whether to display the button for selecting the original image.
The value **true** means to display the button; the value **false** means the opposite.
Default value: **false**
**Atomic service API**: This API can be used in atomic services since API version 12. | | subWindowName12+ | string | No | Name of the sub-window.
**Atomic service API**: This API can be used in atomic services since API version 12. | | complteButtonText14+ | [CompleteButtonText](#completebuttontext14) | No | Text displayed on the complete button.
The complete button is located in the lower right corner of the page. It is used by users to signify that they have finished selecting images.
**Atomic service API**: This API can be used in atomic services since API version 14. | ## PhotoSelectResult Defines information about the images or videos selected. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core | Name | Type | Readable| Writable| Description | | ----------------------- | ------------------- | ---- | ---- | ------------------------------ | | photoUris | Array<string> | Yes | Yes | URIs of the images or videos selected. The URI array can be used only by calling [photoAccessHelper.getAssets](#getassets) with temporary authorization. For details about how to use the media file URI, see [Using a Media File URI](../../file-management/user-file-uri-intro.md#using-a-media-file-uri).| | isOriginalPhoto | boolean | Yes | Yes | Whether the selected media asset is the original image.| ## DeliveryMode11+ Enumerates the asset delivery modes. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core | Name | Value| Description| | ----- | ---- | ---- | | FAST_MODE | 0 | Fast mode.| | HIGH_QUALITY_MODE | 1 | High-quality mode.| | BALANCE_MODE | 2 | Balance mode.| ## PhotoCreationConfig12+ Represents the configuration for saving a media asset (image or video) to the media library, including the file name. **Atomic service API**: This API can be used in atomic services since API version 12. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core | Name | Type | Mandatory| Description | | ---------------------- | ------------------- | ---- | ------------------------------------------------ | | title | string | No | Title of the image or video.| | fileNameExtension | string | Yes | File name extension, for example, **'jpg'**.| | photoType | [PhotoType](#phototype) | Yes | Type of the file to create, which can be **IMAGE** or **VIDEO**.| | subtype | [PhotoSubtype](#photosubtype12) | No | Subtype of the image or video file, which can be **DEFAULT** or **MOVING_PHOTO**.| ## CompleteButtonText14+ Enumerates the text displayed on the complete button. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core | Name | Value| Description| | ----- | ---- | ---- | | TEXT_DONE14+ | 0 | The text "Done" is displayed. | | TEXT_SEND14+ | 1 | The text "Send" is displayed. | | TEXT_ADD14+ | 2 | The text "Add" is displayed. |