1# @ohos.file.sendablePhotoAccessHelper (Album Management Based on a Sendable object) 2 3The **sendablePhotoAccessHelper** module provides APIs for album management, including creating an album and accessing and modifying media data in an album, based on a sendable object. 4 5> **NOTE** 6> 7> The initial APIs of this module are supported since API version 12. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8 9## Modules to Import 10 11```ts 12import { sendablePhotoAccessHelper } from '@kit.MediaLibraryKit'; 13``` 14 15## sendablePhotoAccessHelper.getPhotoAccessHelper 16 17getPhotoAccessHelper(context: Context): PhotoAccessHelper 18 19Obtains a **PhotoAccessHelper** instance, which can be used for accessing and modifying media files in an album. 20 21**Model restriction**: This API can be used only in the stage model. 22 23**Atomic service API**: This API can be used in atomic services since API version 12. 24 25**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 26 27**Parameters** 28 29| Name | Type | Mandatory| Description | 30| ------- | ------------------------------------------------------------ | ---- | -------------------------- | 31| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.| 32 33**Return value** 34 35| Type | Description | 36| --------------------------------------- | :------------------- | 37| [PhotoAccessHelper](#photoaccesshelper) | **PhotoAccessHelper** instance obtained.| 38 39**Error codes** 40 41For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 42 43| ID| Error Message | 44| -------- | ------------------------------------------------------------ | 45| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 46 47**Example** 48 49```ts 50// 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. 51let context = getContext(this); 52let phAccessHelper = sendablePhotoAccessHelper.getPhotoAccessHelper(context); 53``` 54 55## PhotoAccessHelper 56 57### getAssets 58 59getAssets(options: FetchOptions): Promise<FetchResult<PhotoAsset>> 60 61Obtains media assets. This API uses a promise to return the result. 62 63**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 64 65**Required permissions**: ohos.permission.READ_IMAGEVIDEO 66 67If 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). 68 69**Parameters** 70 71| Name | Type | Mandatory| Description | 72| ------- | --------------------------------------------------------- | ---- | -------------------- | 73| options | [FetchOptions](js-apis-photoAccessHelper.md#fetchoptions) | Yes | Options for fetching the media assets.| 74 75**Return value** 76 77| Type | Description | 78| ------------------------------------------------------------ | --------------------------------------- | 79| Promise<[FetchResult](#fetchresult)<[PhotoAsset](#photoasset)>> | Promise used to return the media assets obtained.| 80 81**Error codes** 82 83For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 84 85| ID| Error Message | 86| -------- | ------------------------------------------------------------ | 87| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 88| 201 | Permission denied. | 89| 13900020 | Invalid argument. | 90| 14000011 | Internal system error | 91 92**Example** 93 94 95 96```ts 97import { dataSharePredicates } from '@kit.ArkData'; 98import { photoAccessHelper } from '@kit.MediaLibraryKit'; 99 100async function example() { 101 console.info('getAssets'); 102 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 103 let fetchOptions: photoAccessHelper.FetchOptions = { 104 fetchColumns: [], 105 predicates: predicates 106 }; 107 try { 108 let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 109 if (fetchResult !== undefined) { 110 console.info('fetchResult success'); 111 let photoAsset: sendablePhotoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 112 if (photoAsset !== undefined) { 113 console.info('photoAsset.displayName :' + photoAsset.displayName); 114 } 115 } 116 } catch (err) { 117 console.error(`getAssets failed, error: ${err.code}, ${err.message}`); 118 } 119} 120``` 121 122### getBurstAssets 123 124getBurstAssets(burstKey: string, options: FetchOptions): Promise<FetchResult<PhotoAsset>> 125 126Obtains burst assets. This API uses a promise to return the result. 127 128**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 129 130**Required permissions**: ohos.permission.READ_IMAGEVIDEO 131 132**Parameters** 133 134| Name | Type | Mandatory| Description | 135| -------- | --------------------------------------------------------- | ---- | ------------------------------------------------------------ | 136| burstKey | string | Yes | Universally Unique Identifier (UUID) of a group of burst photos, that is, **BURST_KEY** of [PhotoKeys](js-apis-photoAccessHelper.md#photokeys).| 137| options | [FetchOptions](js-apis-photoAccessHelper.md#fetchoptions) | Yes | Options for fetching the burst photos. | 138 139**Return value** 140 141| Type | Description | 142| ------------------------------------------------------------ | ------------------------------------- | 143| Promise<[FetchResult](#fetchresult)<[PhotoAsset](#photoasset)>> | Promise used to return the result.| 144 145**Error codes** 146 147For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 148 149| ID| Error Message | 150| -------- | ------------------------------------------------------------ | 151| 201 | Permission denied. | 152| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 153| 14000011 | Internal system error. | 154 155**Example** 156 157```ts 158import { photoAccessHelper } from '@kit.MediaLibraryKit'; 159import { dataSharePredicates } from '@kit.ArkData'; 160 161async function example() { 162 console.info('getBurstAssets'); 163 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 164 let fetchOption: photoAccessHelper.FetchOptions = { 165 fetchColumns: [], 166 predicates: predicates 167 }; 168 let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 169 let photoAssetList: Array<sendablePhotoAccessHelper.PhotoAsset> = await fetchResult.getAllObjects(); 170 let photoAsset: sendablePhotoAccessHelper.PhotoAsset; 171 // burstKey is a 36-bit UUID, which can be obtained from photoAccessHelper.PhotoKeys. 172 for(photoAsset of photoAssetList){ 173 let burstKey: string = photoAccessHelper.PhotoKeys.BURST_KEY.toString(); 174 let photoAccessBurstKey: photoAccessHelper.MemberType = photoAsset.get(burstKey).toString(); 175 try { 176 let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await 177 phAccessHelper.getBurstAssets(photoAccessBurstKey, fetchOption); 178 if (fetchResult !== undefined) { 179 console.info('fetchResult success'); 180 let photoAsset: sendablePhotoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 181 if (photoAsset !== undefined) { 182 console.info('photoAsset.displayName :' + photoAsset.displayName); 183 } 184 } 185 } catch (err) { 186 console.error(`getBurstAssets failed, error: ${err.code}, ${err.message}`); 187 } 188} 189} 190``` 191 192### createAsset 193 194createAsset(photoType: PhotoType, extension: string, options?: CreateOptions): Promise<string> 195 196Creates a media asset with the specified file type, file name extension, and options. This API uses a promise to return the result. 197 198If 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). 199 200**Atomic service API**: This API can be used in atomic services since API version 12. 201 202**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 203 204**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 205 206**Parameters** 207 208| Name | Type | Mandatory| Description | 209| --------- | ----------------------------------------------------------- | ---- | ------------------------------------ | 210| photoType | [PhotoType](#phototype) | Yes | Type of the file to create, which can be **IMAGE** or **VIDEO**.| 211| extension | string | Yes | File name extension, for example, **'jpg'**. | 212| options | [CreateOptions](js-apis-photoAccessHelper.md#createoptions) | No | Options for creating the media asset, for example, **{title: 'testPhoto'}**.| 213 214**Return value** 215 216| Type | Description | 217| --------------------- | ---------------------------------------- | 218| Promise<string> | Promise used to return the URI of the created media asset.| 219 220**Error codes** 221 222For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 223 224| ID| Error Message | 225| -------- | ------------------------------------------------------------ | 226| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 227| 201 | Permission denied. | 228| 13900020 | Invalid argument. | 229| 14000011 | Internal system error | 230 231**Example** 232 233```ts 234import { photoAccessHelper } from '@kit.MediaLibraryKit'; 235 236async function example() { 237 console.info('createAssetDemo'); 238 try { 239 let photoType: sendablePhotoAccessHelper.PhotoType = sendablePhotoAccessHelper.PhotoType.IMAGE; 240 let extension: string = 'jpg'; 241 let options: photoAccessHelper.CreateOptions = { 242 title: 'testPhoto' 243 } 244 let uri: string = await phAccessHelper.createAsset(photoType, extension, options); 245 console.info('createAsset uri' + uri); 246 console.info('createAsset successfully'); 247 } catch (err) { 248 console.error(`createAsset failed, error: ${err.code}, ${err.message}`); 249 } 250} 251``` 252 253### getAlbums 254 255getAlbums(type: AlbumType, subtype: AlbumSubtype, options?: FetchOptions): Promise<FetchResult<Album>> 256 257Obtains albums based on the specified options and album type. This API uses a promise to return the result. 258 259Before the operation, ensure that the albums to obtain exist. 260 261**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 262 263**Required permissions**: ohos.permission.READ_IMAGEVIDEO 264 265**Parameters** 266 267| Name | Type | Mandatory| Description | 268| ------- | --------------------------------------------------------- | ---- | -------------------------------------- | 269| type | [AlbumType](#albumtype) | Yes | Type of the albums to obtain. | 270| subtype | [AlbumSubtype](#albumsubtype) | Yes | Subtype of the album. | 271| options | [FetchOptions](js-apis-photoAccessHelper.md#fetchoptions) | No | Options for fetching the albums. If this parameter is not specified, the albums are obtained based on the album type by default.| 272 273**Return value** 274 275| Type | Description | 276| ------------------------------------------------------------ | ----------------------------------- | 277| Promise<[FetchResult](#fetchresult)<[Album](#album)>> | Promise used to return the result.| 278 279**Error codes** 280 281For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 282 283| ID| Error Message | 284| -------- | ------------------------------------------------------------ | 285| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 286| 201 | Permission denied. | 287| 13900020 | Invalid argument. | 288| 14000011 | Internal system error | 289 290**Example** 291 292```ts 293import { dataSharePredicates } from '@kit.ArkData'; 294import { BusinessError } from '@kit.BasicServicesKit'; 295import { photoAccessHelper } from '@kit.MediaLibraryKit'; 296 297async function example() { 298 // Obtain the album named newAlbumName. 299 console.info('getAlbumsDemo'); 300 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 301 predicates.equalTo('album_name', 'newAlbumName'); 302 let fetchOptions: photoAccessHelper.FetchOptions = { 303 fetchColumns: [], 304 predicates: predicates 305 }; 306 phAccessHelper.getAlbums(sendablePhotoAccessHelper.AlbumType.USER, sendablePhotoAccessHelper.AlbumSubtype.USER_GENERIC, fetchOptions).then( async (fetchResult) => { 307 if (fetchResult === undefined) { 308 console.error('getAlbumsPromise fetchResult is undefined'); 309 return; 310 } 311 let album: sendablePhotoAccessHelper.Album = await fetchResult.getFirstObject(); 312 console.info('getAlbumsPromise successfully, albumName: ' + album.albumName); 313 fetchResult.close(); 314 }).catch((err: BusinessError) => { 315 console.error(`getAlbumsPromise failed with err: ${err.code}, ${err.message}`); 316 }); 317} 318``` 319 320### getAlbums 321 322getAlbums(options: FetchOptions): Promise<FetchResult<Album>> 323 324Obtains albums. This API uses a promise to return the result. 325 326Before the operation, ensure that the albums to obtain exist. 327 328**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 329 330**Required permissions**: ohos.permission.READ_IMAGEVIDEO 331 332**Parameters** 333 334| Name | Type | Mandatory| Description | 335| ------- | --------------------------------------------------------- | ---- | -------- | 336| options | [FetchOptions](js-apis-photoAccessHelper.md#fetchoptions) | Yes | Options for obtaining the albums.| 337 338**Return value** 339 340| Type | Description | 341| ------------------------------------------------------------ | ----------------------------------- | 342| Promise<[FetchResult](#fetchresult)<[Album](#album)>> | Promise used to return the result.| 343 344**Error codes** 345 346For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 347 348| ID| Error Message | 349| -------- | ------------------------------------------------------------ | 350| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 351| 201 | Permission denied. | 352| 13900020 | Invalid argument. | 353| 14000011 | Internal system error | 354 355**Example** 356 357```ts 358import { dataSharePredicates } from '@kit.ArkData'; 359import { BusinessError } from '@kit.BasicServicesKit'; 360import { photoAccessHelper } from '@kit.MediaLibraryKit'; 361 362async function example() { 363 // Obtain the album named newAlbumName. 364 console.info('getAlbumsDemo'); 365 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 366 predicates.equalTo('album_name', 'newAlbumName'); 367 let fetchOptions: photoAccessHelper.FetchOptions = { 368 fetchColumns: [], 369 predicates: predicates 370 }; 371 phAccessHelper.getAlbums(fetchOptions).then( async (fetchResult) => { 372 if (fetchResult === undefined) { 373 console.error('getAlbumsPromise fetchResult is undefined'); 374 return; 375 } 376 let album: sendablePhotoAccessHelper.Album = await fetchResult.getFirstObject(); 377 console.info('getAlbumsPromise successfully, albumName: ' + album.albumName); 378 fetchResult.close(); 379 }).catch((err: BusinessError) => { 380 console.error(`getAlbumsPromise failed with err: ${err.code}, ${err.message}`); 381 }); 382} 383``` 384 385### release 386 387release(): Promise<void> 388 389Releases this **PhotoAccessHelper** instance. This API uses a promise to return the result. 390Call this API when the APIs of the **PhotoAccessHelper** instance are no longer used. 391 392**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 393 394**Return value** 395 396| Type | Description | 397| ------------------- | ----------------------- | 398| Promise<void> | Promise that returns no value.| 399 400**Error codes** 401 402For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 403 404| ID| Error Message | 405| -------- | ------------------------------------------------------------ | 406| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 407| 13900020 | Invalid argument. | 408| 14000011 | Internal system error | 409 410**Example** 411 412```ts 413async function example() { 414 console.info('releaseDemo'); 415 try { 416 console.info('use function...'); 417 } catch (err) { 418 console.error(`function error ...`); 419 }finally{ 420 try{ 421 phAccessHelper?.release(); 422 console.info(`release success`); 423 } catch(e){ 424 console.error(`release error :${e}`); 425 } 426 } 427} 428``` 429 430## PhotoAsset 431 432Provides APIs for encapsulating file asset attributes. 433 434### Properties 435 436**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 437 438| Name | Type | Read-Only| Optional| Description | 439| ----------- | ----------------------- | ---- | ---- | ------------------------------------------------------------ | 440| 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).| 441| photoType | [PhotoType](#phototype) | Yes | No | Type of the file. | 442| displayName | string | Yes | No | File name, including the file name extension, to display. | 443 444### convertToPhotoAsset 445 446convertToPhotoAsset(): photoAccessHelper.PhotoAsset 447 448Converts a sendable **PhotoAsset** object to a non-sendable **PhotoAsset** object. 449 450**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 451 452**Return value** 453 454| Type | Description | 455| ---------------------------- | ------------------------------------------------------------ | 456| photoAccessHelper.PhotoAsset | [PhotoAsset](js-apis-photoAccessHelper.md#photoasset) object of the non-sendable type.| 457 458**Error codes** 459 460For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 461 462| ID| Error Message | 463| -------- | ------------------------------------------------------------ | 464| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 465| 13900020 | Invalid argument. | 466| 14000014 | Member is not a valid PhotoKey. | 467 468**Example** 469 470```ts 471import { dataSharePredicates } from '@kit.ArkData'; 472import { photoAccessHelper } from '@kit.MediaLibraryKit'; 473 474async function example() { 475 console.info('convertToPhotoAssetDemo'); 476 try { 477 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 478 let fetchOption: photoAccessHelper.FetchOptions = { 479 fetchColumns: ['title'], 480 predicates: predicates 481 }; 482 let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 483 let sendablePhotoAsset: sendablePhotoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 484 let photoAsset: photoAccessHelper.PhotoAsset = sendablePhotoAsset.convertToPhotoAsset(); 485 console.log(`get no sendable uri success : ${photoAsset.uri}`); 486 } catch (err) { 487 console.error(`convertToPhotoAsset failed. error: ${err.code}, ${err.message}`); 488 } 489} 490``` 491 492### get 493 494get(member: string): MemberType 495 496Obtains a **PhotoAsset** member parameter. 497 498**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 499 500**Parameters** 501 502| Name| Type | Mandatory| Description | 503| ------ | ------ | ---- | ------------------------------------------------------------ | 504| member | string | Yes | Name of the member parameter to obtain. <br>Except **'uri'**, **'media_type'**, **'subtype'**, and **'display_name'**, you must pass in [PhotoKeys](js-apis-photoAccessHelper.md#photokeys) in **fetchColumns**. For example, to obtain the title, pass in **fetchColumns: ['title']**.| 505 506**Return value** 507 508| Type | Description | 509| ----------------------------------------------------- | ---------------------------- | 510| [MemberType](js-apis-photoAccessHelper.md#membertype) | **PhotoAsset** member parameter obtained.| 511 512**Error codes** 513 514For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 515 516| ID| Error Message | 517| -------- | ------------------------------------------------------------ | 518| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 519| 13900020 | Invalid argument. | 520| 14000014 | Member is not a valid PhotoKey. | 521 522**Example** 523 524```ts 525import { dataSharePredicates } from '@kit.ArkData'; 526import { photoAccessHelper } from '@kit.MediaLibraryKit'; 527 528async function example() { 529 console.info('photoAssetGetDemo'); 530 try { 531 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 532 let fetchOption: photoAccessHelper.FetchOptions = { 533 fetchColumns: ['title'], 534 predicates: predicates 535 }; 536 let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 537 let photoAsset: sendablePhotoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 538 let title: photoAccessHelper.PhotoKeys = photoAccessHelper.PhotoKeys.TITLE; 539 let photoAssetTitle: photoAccessHelper.MemberType = photoAsset.get(title.toString()); 540 console.info('photoAsset Get photoAssetTitle = ', photoAssetTitle); 541 } catch (err) { 542 console.error(`get failed. error: ${err.code}, ${err.message}`); 543 } 544} 545``` 546 547### set 548 549set(member: string, value: string): void 550 551Sets a **PhotoAsset** member parameter. 552 553**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 554 555**Parameters** 556 557| Name| Type | Mandatory| Description | 558| ------ | ------ | ---- | ------------------------------------------------------------ | 559| member | string | Yes | Name of the parameter to set, for example, [PhotoKeys](js-apis-photoAccessHelper.md#photokeys).TITLE.| 560| value | string | Yes | Value to set. Only the value of [PhotoKeys](js-apis-photoAccessHelper.md#photokeys).TITLE can be changed.| 561 562**Error codes** 563 564For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 565 566| ID| Error Message | 567| -------- | ------------------------------------------------------------ | 568| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 569| 13900020 | Invalid argument. | 570| 14000014 | Member is not a valid PhotoKey. | 571 572**Example** 573 574```ts 575import { dataSharePredicates } from '@kit.ArkData'; 576import { photoAccessHelper } from '@kit.MediaLibraryKit'; 577 578async function example() { 579 console.info('photoAssetSetDemo'); 580 try { 581 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 582 let fetchOption: photoAccessHelper.FetchOptions = { 583 fetchColumns: ['title'], 584 predicates: predicates 585 }; 586 let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 587 let photoAsset: sendablePhotoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 588 let title: string = photoAccessHelper.PhotoKeys.TITLE.toString(); 589 photoAsset.set(title, 'newTitle'); 590 } catch (err) { 591 console.error(`set failed. error: ${err.code}, ${err.message}`); 592 } 593} 594``` 595 596### commitModify 597 598commitModify(): Promise<void> 599 600Commits the modification on the file metadata to the database. This API uses a promise to return the result. 601 602**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 603 604**Atomic service API**: This API can be used in atomic services since API version 12. 605 606**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 607 608**Return value** 609 610| Type | Description | 611| ------------------- | ----------------------- | 612| Promise<void> | Promise that returns no value.| 613 614**Error codes** 615 616For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 617 618| ID| Error Message | 619| -------- | ------------------------------------------------------------ | 620| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 621| 201 | Permission denied. | 622| 13900020 | Invalid argument. | 623| 14000001 | Invalid display name. | 624| 14000011 | Internal system error | 625 626**Example** 627 628```ts 629import { dataSharePredicates } from '@kit.ArkData'; 630 631async function example() { 632 console.info('commitModifyDemo'); 633 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 634 let fetchOption: photoAccessHelper.FetchOptions = { 635 fetchColumns: ['title'], 636 predicates: predicates 637 }; 638 let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 639 let photoAsset: sendablePhotoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 640 let title: string = photoAccessHelper.PhotoKeys.TITLE.toString(); 641 let photoAssetTitle: photoAccessHelper.MemberType = photoAsset.get(title); 642 console.info('photoAsset get photoAssetTitle = ', photoAssetTitle); 643 photoAsset.set(title, 'newTitle3'); 644 try { 645 await photoAsset.commitModify(); 646 let newPhotoAssetTitle: photoAccessHelper.MemberType = photoAsset.get(title); 647 console.info('photoAsset get newPhotoAssetTitle = ', newPhotoAssetTitle); 648 } catch (err) { 649 console.error(`commitModify failed. error: ${err.code}, ${err.message}`); 650 } 651} 652``` 653 654### getThumbnail 655 656getThumbnail(size?: image.Size): Promise<image.PixelMap> 657 658Obtains the file thumbnail of the given size. This API uses a promise to return the result. 659 660**Required permissions**: ohos.permission.READ_IMAGEVIDEO 661 662**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 663 664**Parameters** 665 666| Name| Type | Mandatory| Description | 667| ------ | ----------------------------------------------------- | ---- | ------------ | 668| size | [image.Size](../apis-image-kit/js-apis-image.md#size) | No | Size of the thumbnail.| 669 670**Return value** 671 672| Type | Description | 673| ------------------------------------------------------------ | ----------------------------------- | 674| Promise<[image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)> | Promise used to return the PixelMap of the thumbnail.| 675 676**Error codes** 677 678For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 679 680| ID| Error Message | 681| -------- | ------------------------------------------------------------ | 682| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 683| 201 | Permission denied. | 684| 13900020 | Invalid argument. | 685| 14000011 | Internal system error | 686 687**Example** 688 689```ts 690import { dataSharePredicates } from '@kit.ArkData'; 691import { image } from '@kit.ImageKit'; 692import { BusinessError } from '@kit.BasicServicesKit'; 693import { photoAccessHelper } from '@kit.MediaLibraryKit'; 694 695async function example() { 696 console.info('getThumbnailDemo'); 697 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 698 let fetchOption: photoAccessHelper.FetchOptions = { 699 fetchColumns: [], 700 predicates: predicates 701 }; 702 let size: image.Size = { width: 720, height: 720 }; 703 let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 704 let asset = await fetchResult.getFirstObject(); 705 console.info('asset displayName = ', asset.displayName); 706 asset.getThumbnail(size).then((pixelMap) => { 707 console.info('getThumbnail successful ' + pixelMap); 708 }).catch((err: BusinessError) => { 709 console.error(`getThumbnail fail with error: ${err.code}, ${err.message}`); 710 }); 711} 712``` 713 714## FetchResult 715 716Provides APIs to manage the file retrieval result. 717 718### getCount 719 720getCount(): number 721 722Obtains the total number of files in the result set. 723 724**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 725 726**Return value** 727 728| Type | Description | 729| ------ | ------------------ | 730| number | Total number of files obtained.| 731 732**Error codes** 733 734For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 735 736| ID| Error Message | 737| -------- | ------------------------------------------------------------ | 738| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 739| 13900020 | Invalid argument. | 740| 14000011 | Internal system error | 741 742**Example** 743 744```ts 745import { dataSharePredicates } from '@kit.ArkData'; 746import { photoAccessHelper } from '@kit.MediaLibraryKit'; 747 748async function example() { 749 console.info('getCountDemo'); 750 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 751 let fetchOption: photoAccessHelper.FetchOptions = { 752 fetchColumns: [], 753 predicates: predicates 754 }; 755 let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 756 let fetchCount = fetchResult.getCount(); 757 console.info('fetchCount = ', fetchCount); 758} 759``` 760 761### isAfterLast 762 763isAfterLast(): boolean 764 765Checks whether the cursor is in the last row of the result set. 766 767**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 768 769**Return value** 770 771| Type | Description | 772| ------- | ----------------------------------------------------------- | 773| boolean | Returns **true** if the cursor is in the last row of the result set; returns **false** otherwise.| 774 775**Error codes** 776 777For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 778 779| ID| Error Message | 780| -------- | ------------------------------------------------------------ | 781| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 782| 13900020 | Invalid argument. | 783| 14000011 | Internal system error | 784 785**Example** 786 787```ts 788import { dataSharePredicates } from '@kit.ArkData'; 789import { photoAccessHelper } from '@kit.MediaLibraryKit'; 790 791async function example() { 792 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 793 let fetchOption: photoAccessHelper.FetchOptions = { 794 fetchColumns: [], 795 predicates: predicates 796 }; 797 let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 798 let fetchCount = fetchResult.getCount(); 799 console.info('count:' + fetchCount); 800 let photoAsset: sendablePhotoAccessHelper.PhotoAsset = await fetchResult.getLastObject(); 801 if (fetchResult.isAfterLast()) { 802 console.info('photoAsset isAfterLast displayName = ', photoAsset.displayName); 803 } else { 804 console.info('photoAsset not isAfterLast.'); 805 } 806} 807``` 808 809### close 810 811close(): void 812 813Closes this **FetchFileResult** instance to invalidate it. After this instance is closed, the APIs in this instance cannot be invoked. 814 815**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 816 817**Error codes** 818 819For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 820 821| ID| Error Message | 822| -------- | ------------------------------------------------------------ | 823| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 824| 13900020 | Invalid argument. | 825| 14000011 | Internal system error | 826 827**Example** 828 829```ts 830import { dataSharePredicates } from '@kit.ArkData'; 831import { photoAccessHelper } from '@kit.MediaLibraryKit'; 832 833async function example() { 834 console.info('fetchResultCloseDemo'); 835 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 836 let fetchOption: photoAccessHelper.FetchOptions = { 837 fetchColumns: [], 838 predicates: predicates 839 }; 840 try { 841 let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 842 fetchResult.close(); 843 console.info('close succeed.'); 844 } catch (err) { 845 console.error(`close fail. error: ${err.code}, ${err.message}`); 846 } 847} 848``` 849 850### getFirstObject 851 852getFirstObject(): Promise<T> 853 854Obtains the first asset in the result set. This API uses a promise to return the result. 855 856**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 857 858**Return value** 859 860| Type | Description | 861| ---------------- | ------------------------------------- | 862| Promise<T> | Promise used to return the first object in the result set.| 863 864**Error codes** 865 866For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 867 868| ID| Error Message | 869| -------- | ------------------------------------------------------------ | 870| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 871| 13900020 | Invalid argument. | 872| 14000011 | Internal system error | 873 874**Example** 875 876```ts 877import { dataSharePredicates } from '@kit.ArkData'; 878import { photoAccessHelper } from '@kit.MediaLibraryKit'; 879 880async function example() { 881 console.info('getFirstObjectDemo'); 882 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 883 let fetchOption: photoAccessHelper.FetchOptions = { 884 fetchColumns: [], 885 predicates: predicates 886 }; 887 let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 888 let photoAsset: sendablePhotoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 889 console.info('photoAsset displayName: ', photoAsset.displayName); 890} 891``` 892 893### getNextObject 894 895getNextObject(): Promise<T> 896 897Obtains the next asset in the result set. This API uses a promise to return the result. 898Before using this API, you must use [isAfterLast()](#isafterlast) to check whether the current position is the end of the result set. 899 900**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 901 902**Return value** 903 904| Type | Description | 905| ---------------- | ------------------------------------- | 906| Promise<T> | Promise used to return the next object in the result set.| 907 908**Error codes** 909 910For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 911 912| ID| Error Message | 913| -------- | ------------------------------------------------------------ | 914| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 915| 13900020 | Invalid argument. | 916| 14000011 | Internal system error | 917 918**Example** 919 920```ts 921import { dataSharePredicates } from '@kit.ArkData'; 922import { photoAccessHelper } from '@kit.MediaLibraryKit'; 923 924async function example() { 925 console.info('getNextObjectDemo'); 926 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 927 let fetchOption: photoAccessHelper.FetchOptions = { 928 fetchColumns: [], 929 predicates: predicates 930 }; 931 let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 932 await fetchResult.getFirstObject(); 933 let photoAsset: sendablePhotoAccessHelper.PhotoAsset = await fetchResult.getNextObject(); 934 console.info('photoAsset displayName: ', photoAsset.displayName); 935} 936``` 937 938### getLastObject 939 940getLastObject(): Promise<T> 941 942Obtains the last asset in the result set. This API uses a promise to return the result. 943 944**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 945 946**Return value** 947 948| Type | Description | 949| ---------------- | --------------------------------------- | 950| Promise<T> | Promise used to return the last object in the result set.| 951 952**Error codes** 953 954For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 955 956| ID| Error Message | 957| -------- | ------------------------------------------------------------ | 958| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 959| 13900020 | Invalid argument. | 960| 14000011 | Internal system error | 961 962**Example** 963 964```ts 965import { dataSharePredicates } from '@kit.ArkData'; 966import { photoAccessHelper } from '@kit.MediaLibraryKit'; 967 968async function example() { 969 console.info('getLastObjectDemo'); 970 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 971 let fetchOption: photoAccessHelper.FetchOptions = { 972 fetchColumns: [], 973 predicates: predicates 974 }; 975 let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 976 let photoAsset: sendablePhotoAccessHelper.PhotoAsset = await fetchResult.getLastObject(); 977 console.info('photoAsset displayName: ', photoAsset.displayName); 978} 979``` 980 981### getObjectByPosition 982 983getObjectByPosition(index: number): Promise<T> 984 985Obtains the asset with the given index in the result set. This API uses a promise to return the result. 986 987**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 988 989**Parameters** 990 991| Name| Type | Mandatory| Description | 992| ------ | ------ | ---- | ----------------------------- | 993| index | number | Yes | Index of the asset to obtain. The value starts from **0**.| 994 995**Return value** 996 997| Type | Description | 998| ---------------- | --------------------------------------------- | 999| Promise<T> | Promise used to return the asset obtained.| 1000 1001**Error codes** 1002 1003For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1004 1005| ID| Error Message | 1006| -------- | ------------------------------------------------------------ | 1007| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1008| 13900020 | Invalid argument. | 1009| 14000011 | Internal system error | 1010 1011**Example** 1012 1013```ts 1014import { dataSharePredicates } from '@kit.ArkData'; 1015import { photoAccessHelper } from '@kit.MediaLibraryKit'; 1016 1017async function example() { 1018 console.info('getObjectByPositionDemo'); 1019 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1020 let fetchOption: photoAccessHelper.FetchOptions = { 1021 fetchColumns: [], 1022 predicates: predicates 1023 }; 1024 let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 1025 let photoAsset: sendablePhotoAccessHelper.PhotoAsset = await fetchResult.getObjectByPosition(0); 1026 console.info('photoAsset displayName: ', photoAsset.displayName); 1027} 1028``` 1029 1030### getAllObjects 1031 1032getAllObjects(): Promise<Array<T>> 1033 1034Obtains all the file assets in the result set. This API uses a promise to return the result. 1035 1036**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1037 1038**Return value** 1039 1040| Type | Description | 1041| ----------------------------- | ------------------------------------------- | 1042| Promise<Array<T>> | Promise used to return all the assets in the result set.| 1043 1044**Error codes** 1045 1046For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1047 1048| ID| Error Message | 1049| -------- | ------------------------------------------------------------ | 1050| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1051| 13900020 | Invalid argument. | 1052| 14000011 | Internal system error | 1053 1054**Example** 1055 1056```ts 1057import { dataSharePredicates } from '@kit.ArkData'; 1058import { photoAccessHelper } from '@kit.MediaLibraryKit'; 1059 1060async function example() { 1061 console.info('getAllObjectDemo'); 1062 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1063 let fetchOption: photoAccessHelper.FetchOptions = { 1064 fetchColumns: [], 1065 predicates: predicates 1066 }; 1067 let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 1068 let photoAssetList: Array<sendablePhotoAccessHelper.PhotoAsset> = await fetchResult.getAllObjects(); 1069 console.info('photoAssetList length: ', photoAssetList.length); 1070} 1071``` 1072 1073## Album 1074 1075Provides APIs to manage albums. 1076 1077### Properties 1078 1079**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1080 1081| Name | Type | Read-Only | Optional| Description | 1082| ------------ | ----------------------------- | ---------------------------- | ---- | ---------------- | 1083| albumType | [AlbumType](#albumtype) | Yes | No | Type of the album. | 1084| albumSubtype | [AlbumSubtype](#albumsubtype) | Yes | No | Subtype of the album. | 1085| albumName | string | Yes for a user album; no for a system album.| No | Name of the album. | 1086| albumUri | string | Yes | No | URI of the album. | 1087| count | number | Yes | No | Number of files in the album.| 1088| coverUri | string | Yes | No | URI of the cover file of the album. | 1089| imageCount | number | Yes | Yes | Number of images in the album.| 1090| videoCount | number | Yes | Yes | Number of videos in the album.| 1091 1092### convertToPhotoAlbum 1093 1094convertToPhotoAlbum(): photoAccessHelper.Album 1095 1096Converts this sendable album to a non-sendable album. 1097 1098**Required permissions**: ohos.permission.READ_IMAGEVIDEO 1099 1100**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1101 1102**Return value** 1103 1104| Type | Description | 1105| ----------------------- | --------------------------------------------------------- | 1106| photoAccessHelper.Album | Non-sendable [Album](js-apis-photoAccessHelper.md#album).| 1107 1108**Error codes** 1109 1110For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1111 1112| ID| Error Message | 1113| -------- | ------------------------------------------------------------ | 1114| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1115| 201 | Permission denied. | 1116| 13900020 | Invalid argument. | 1117| 14000011 | Internal system error | 1118 1119**Example** 1120 1121```ts 1122import { dataSharePredicates } from '@kit.ArkData'; 1123import { BusinessError } from '@kit.BasicServicesKit'; 1124import { photoAccessHelper } from '@kit.MediaLibraryKit'; 1125 1126async function example() { 1127 console.info('convertToPhotoAlbumDemo'); 1128 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1129 let albumFetchOptions: photoAccessHelper.FetchOptions = { 1130 fetchColumns: [], 1131 predicates: predicates 1132 }; 1133 let fetchOption: photoAccessHelper.FetchOptions = { 1134 fetchColumns: [], 1135 predicates: predicates 1136 }; 1137 let albumList: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.Album> = await phAccessHelper.getAlbums(sendablePhotoAccessHelper.AlbumType.USER, sendablePhotoAccessHelper.AlbumSubtype.USER_GENERIC, albumFetchOptions); 1138 let sendableAlbum: sendablePhotoAccessHelper.Album = await albumList.getFirstObject(); 1139 let album: photoAccessHelper.Album = sendableAlbum.convertToPhotoAlbum(); 1140 album.getAssets(fetchOption).then((albumFetchResult) => { 1141 console.info('convertToPhotoAlbum successfully, getCount: ' + albumFetchResult.getCount()); 1142 }).catch((err: BusinessError) => { 1143 console.error(`convertToPhotoAlbum failed with error: ${err.code}, ${err.message}`); 1144 }); 1145} 1146``` 1147 1148### getAssets 1149 1150getAssets(options: FetchOptions): Promise<FetchResult<PhotoAsset>> 1151 1152Obtains media assets. This API uses a promise to return the result. 1153 1154**Required permissions**: ohos.permission.READ_IMAGEVIDEO 1155 1156**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1157 1158**Parameters** 1159 1160| Name | Type | Mandatory| Description | 1161| ------- | --------------------------------------------------------- | ---- | ---------- | 1162| options | [FetchOptions](js-apis-photoAccessHelper.md#fetchoptions) | Yes | Options for fetching the assets.| 1163 1164**Return value** 1165 1166| Type | Description | 1167| ------------------------------------------------------------ | --------------------------------------- | 1168| Promise<[FetchResult](#fetchresult)<[PhotoAsset](#photoasset)>> | Promise used to return the media assets obtained.| 1169 1170**Error codes** 1171 1172For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1173 1174| ID| Error Message | 1175| -------- | ------------------------------------------------------------ | 1176| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1177| 201 | Permission denied. | 1178| 13900020 | Invalid argument. | 1179| 14000011 | Internal system error | 1180 1181**Example** 1182 1183```ts 1184import { dataSharePredicates } from '@kit.ArkData'; 1185import { BusinessError } from '@kit.BasicServicesKit'; 1186import { photoAccessHelper } from '@kit.MediaLibraryKit'; 1187 1188async function example() { 1189 console.info('albumGetAssetsDemoPromise'); 1190 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1191 let albumFetchOptions: photoAccessHelper.FetchOptions = { 1192 fetchColumns: [], 1193 predicates: predicates 1194 }; 1195 let fetchOption: photoAccessHelper.FetchOptions = { 1196 fetchColumns: [], 1197 predicates: predicates 1198 }; 1199 let albumList: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.Album> = await phAccessHelper.getAlbums(sendablePhotoAccessHelper.AlbumType.USER, sendablePhotoAccessHelper.AlbumSubtype.USER_GENERIC, albumFetchOptions); 1200 let album: sendablePhotoAccessHelper.Album = await albumList.getFirstObject(); 1201 album.getAssets(fetchOption).then((albumFetchResult) => { 1202 console.info('album getAssets successfully, getCount: ' + albumFetchResult.getCount()); 1203 }).catch((err: BusinessError) => { 1204 console.error(`album getAssets failed with error: ${err.code}, ${err.message}`); 1205 }); 1206} 1207``` 1208 1209### commitModify 1210 1211commitModify(): Promise<void> 1212 1213Commits the modification on the album attributes to the database. This API uses a promise to return the result. 1214 1215**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 1216 1217**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1218 1219**Return value** 1220 1221| Type | Description | 1222| ------------------- | ----------------------- | 1223| Promise<void> | Promise that returns no value.| 1224 1225**Error codes** 1226 1227For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1228 1229| ID| Error Message | 1230| -------- | ------------------------------------------------------------ | 1231| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1232| 201 | Permission denied. | 1233| 13900020 | Invalid argument. | 1234| 14000011 | Internal system error | 1235 1236**Example** 1237 1238```ts 1239import { dataSharePredicates } from '@kit.ArkData'; 1240import { BusinessError } from '@kit.BasicServicesKit'; 1241import { photoAccessHelper } from '@kit.MediaLibraryKit'; 1242 1243async function example() { 1244 console.info('albumCommitModifyDemo'); 1245 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1246 let albumFetchOptions: photoAccessHelper.FetchOptions = { 1247 fetchColumns: [], 1248 predicates: predicates 1249 }; 1250 let albumList: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.Album> = await phAccessHelper.getAlbums(sendablePhotoAccessHelper.AlbumType.USER, sendablePhotoAccessHelper.AlbumSubtype.USER_GENERIC, albumFetchOptions); 1251 let album: sendablePhotoAccessHelper.Album = await albumList.getFirstObject(); 1252 album.albumName = 'hello'; 1253 album.commitModify().then(() => { 1254 console.info('commitModify successfully'); 1255 }).catch((err: BusinessError) => { 1256 console.error(`commitModify failed with error: ${err.code}, ${err.message}`); 1257 }); 1258} 1259``` 1260 1261## PhotoType 1262 1263Enumerates media file types. 1264 1265**Atomic service API**: This API can be used in atomic services since API version 12. 1266 1267**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1268 1269| Name | Value | Description | 1270| ----- | ---- | ------ | 1271| IMAGE | 1 | Image.| 1272| VIDEO | 2 | Video.| 1273 1274## AlbumType 1275 1276Enumerates the album types. 1277 1278**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1279 1280| Name | Value | Description | 1281| ------ | ---- | -------------- | 1282| USER | 0 | User album. | 1283| SYSTEM | 1024 | System album.| 1284 1285## AlbumSubtype 1286 1287Enumerate the album subtypes. 1288 1289**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1290 1291| Name | Value | Description | 1292| ------------- | ---------- | ---------- | 1293| USER\_GENERIC | 1 | User album.| 1294| FAVORITE | 1025 | Favorites. | 1295| VIDEO | 1026 | Video album.| 1296| IMAGE | 1031 | Photo album.| 1297| ANY | 2147483647 | Any album.| 1298