1# @ohos.filemanagement.userFileManager (User Data Management) 2 3The **userFileManager** module provides user data management capabilities, including accessing and modifying user media data (audio and video clips, images, and files). 4 5> **NOTE** 6> 7> - The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8> - The APIs provided by this module are system APIs. 9 10## Modules to Import 11 12```ts 13import userFileManager from '@ohos.filemanagement.userFileManager'; 14``` 15 16## userFileManager.getUserFileMgr 17 18getUserFileMgr(context: Context): UserFileManager 19 20Obtains a **UserFileManager** instance. This instance can be used to access and modify user media data (such as audio and video clips, images, and files). 21 22**Model restriction**: This API can be used only in the stage model. 23 24**System capability**: SystemCapability.FileManagement.UserFileManager.Core 25 26**Parameters** 27 28| Name | Type | Mandatory| Description | 29| ------- | ------- | ---- | -------------------------- | 30| context | [Context](js-apis-inner-app-context.md) | Yes | Context of the ability instance.| 31 32**Return value** 33 34| Type | Description | 35| ----------------------------- | :---- | 36| [UserFileManager](#userfilemanager) | **UserFileManager** instance obtained.| 37 38**Example** 39 40```ts 41// The userFileManager 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 mgr is not defined. 42const context = getContext(this); 43let mgr = userFileManager.getUserFileMgr(context); 44``` 45 46## UserFileManager 47 48### getPhotoAssets 49 50getPhotoAssets(options: FetchOptions, callback: AsyncCallback<FetchResult<FileAsset>>): void; 51 52Obtains image and video assets. This API uses an asynchronous callback to return the result. 53 54**System capability**: SystemCapability.FileManagement.UserFileManager.Core 55 56**Required permissions**: ohos.permission.READ_IMAGEVIDEO 57 58**Parameters** 59 60| Name | Type | Mandatory| Description | 61| -------- | ------------------------ | ---- | ------------------------- | 62| options | [FetchOptions](#fetchoptions) | Yes | Options for fetching the image and video assets. | 63| callback | AsyncCallback<[FetchResult](#fetchresult)<[FileAsset](#fileasset)>> | Yes | Callback invoked to return the image and video assets obtained.| 64 65**Error codes** 66 67For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 68 69| ID| Error Message| 70| -------- | ---------------------------------------- | 71| 13900020 | if type options is not FetchOptions. | 72 73**Example** 74 75```ts 76import dataSharePredicates from '@ohos.data.dataSharePredicates'; 77 78async function example() { 79 console.info('getPhotoAssets'); 80 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 81 let fetchOptions: userFileManager.FetchOptions = { 82 fetchColumns: [], 83 predicates: predicates 84 }; 85 86 mgr.getPhotoAssets(fetchOptions, async (err, fetchResult) => { 87 if (fetchResult != undefined) { 88 console.info('fetchResult success'); 89 let fileAsset: userFileManager.FileAsset = await fetchResult.getFirstObject(); 90 if (fileAsset != undefined) { 91 console.info('fileAsset.displayName : ' + fileAsset.displayName); 92 } 93 } else { 94 console.error('fetchResult fail' + err); 95 } 96 }); 97} 98``` 99 100### getPhotoAssets 101 102getPhotoAssets(options: FetchOptions): Promise<FetchResult<FileAsset>>; 103 104Obtains image and video assets. This API uses a promise to return the result. 105 106**System capability**: SystemCapability.FileManagement.UserFileManager.Core 107 108**Required permissions**: ohos.permission.READ_IMAGEVIDEO 109 110**Parameters** 111 112| Name | Type | Mandatory| Description | 113| ------- | ------------------- | ---- | ---------------- | 114| options | [FetchOptions](#fetchoptions) | Yes | Options for fetching the image and video assets. | 115 116**Return value** 117 118| Type | Description | 119| --------------------------- | -------------- | 120| Promise<[FetchResult](#fetchresult)<[FileAsset](#fileasset)>> | Promise used to return the image and video assets obtained.| 121 122**Error codes** 123 124For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 125 126| ID| Error Message| 127| -------- | ---------------------------------------- | 128| 13900020 | if type options is not FetchOptions. | 129 130**Example** 131 132```ts 133import dataSharePredicates from '@ohos.data.dataSharePredicates'; 134 135async function example() { 136 console.info('getPhotoAssets'); 137 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 138 let fetchOptions: userFileManager.FetchOptions = { 139 fetchColumns: [], 140 predicates: predicates 141 }; 142 try { 143 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await mgr.getPhotoAssets(fetchOptions); 144 if (fetchResult != undefined) { 145 console.info('fetchResult success'); 146 let fileAsset: userFileManager.FileAsset = await fetchResult.getFirstObject(); 147 if (fileAsset != undefined) { 148 console.info('fileAsset.displayName :' + fileAsset.displayName); 149 } 150 } 151 } catch (err) { 152 console.error('getPhotoAssets failed, message = ', err); 153 } 154} 155``` 156### createPhotoAsset 157 158createPhotoAsset(displayName: string, albumUri: string, callback: AsyncCallback<FileAsset>): void; 159 160Creates an image or video asset with the specified file name and URI. This API uses an asynchronous callback to return the result. 161 162**System capability**: SystemCapability.FileManagement.UserFileManager.Core 163 164**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 165 166**Parameters** 167 168| Name | Type | Mandatory| Description | 169| -------- | ------------------------ | ---- | ------------------------- | 170| displayName | string | Yes | File name of the image or video to create. | 171| albumUri | string | Yes | URI of the album where the image or video is located. | 172| callback | AsyncCallback<[FileAsset](#fileasset)> | Yes | Callback invoked to return the image or video created.| 173 174**Error codes** 175 176For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 177 178| ID| Error Message| 179| -------- | ---------------------------------------- | 180| 13900020 | if type displayName or albumUri is not string. | 181| 14000001 | if type displayName invalid. | 182 183**Example** 184 185```ts 186import dataSharePredicates from '@ohos.data.dataSharePredicates'; 187 188async function example() { 189 console.info('createPhotoAssetDemo'); 190 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 191 let fetchOptions: userFileManager.AlbumFetchOptions = { 192 predicates: predicates 193 }; 194 let albums: userFileManager.FetchResult<userFileManager.Album> = await mgr.getPhotoAlbums(fetchOptions); 195 let album: userFileManager.Album = await albums.getFirstObject(); 196 let testFileName: string = 'testFile' + Date.now() + '.jpg'; 197 mgr.createPhotoAsset(testFileName, album.albumUri, (err, fileAsset) => { 198 if (fileAsset != undefined) { 199 console.info('createPhotoAsset file displayName' + fileAsset.displayName); 200 console.info('createPhotoAsset successfully'); 201 } else { 202 console.error('createPhotoAsset failed, message = ', err); 203 } 204 }); 205} 206``` 207 208### createPhotoAsset 209 210createPhotoAsset(displayName: string, callback: AsyncCallback<FileAsset>): void; 211 212Creates an image or video asset with the specified file name. This API uses an asynchronous callback to return the result. 213 214**System capability**: SystemCapability.FileManagement.UserFileManager.Core 215 216**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 217 218**Parameters** 219 220| Name | Type | Mandatory| Description | 221| -------- | ------------------------ | ---- | ------------------------- | 222| displayName | string | Yes | File name of the image or video to create. | 223| callback | AsyncCallback<[FileAsset](#fileasset)> | Yes | Callback invoked to return the image or video created.| 224 225**Error codes** 226 227For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 228 229| ID| Error Message| 230| -------- | ---------------------------------------- | 231| 13900020 | if type displayName is not string. | 232| 14000001 | if type displayName invalid. | 233 234**Example** 235 236```ts 237async function example() { 238 console.info('createPhotoAssetDemo'); 239 let testFileName: string = 'testFile' + Date.now() + '.jpg'; 240 mgr.createPhotoAsset(testFileName, (err, fileAsset) => { 241 if (fileAsset != undefined) { 242 console.info('createPhotoAsset file displayName' + fileAsset.displayName); 243 console.info('createPhotoAsset successfully'); 244 } else { 245 console.error('createPhotoAsset failed, message = ', err); 246 } 247 }); 248} 249``` 250 251### createPhotoAsset 252 253createPhotoAsset(displayName: string, albumUri?: string): Promise<FileAsset>; 254 255Creates an image or video asset with the specified file name and URI. This API uses a promise to return the result. 256 257**System capability**: SystemCapability.FileManagement.UserFileManager.Core 258 259**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 260 261**Parameters** 262 263| Name | Type | Mandatory| Description | 264| -------- | ------------------------ | ---- | ------------------------- | 265| displayName | string | Yes | File name of the image or video to create. | 266| albumUri | string | No | URI of the album where the image or video is located. | 267 268**Return value** 269 270| Type | Description | 271| --------------------------- | -------------- | 272| Promise<[FileAsset](#fileasset)> | Promise used to return the created image and video asset.| 273 274**Error codes** 275 276For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 277 278| ID| Error Message| 279| -------- | ---------------------------------------- | 280| 13900020 | if type displayName or albumUri is not string. | 281 282**Example** 283 284```ts 285async function example() { 286 console.info('createPhotoAssetDemo'); 287 try { 288 let testFileName: string = 'testFile' + Date.now() + '.jpg'; 289 let fileAsset: userFileManager.FileAsset = await mgr.createPhotoAsset(testFileName); 290 console.info('createPhotoAsset file displayName' + fileAsset.displayName); 291 console.info('createPhotoAsset successfully'); 292 } catch (err) { 293 console.error('createPhotoAsset failed, message = ', err); 294 } 295} 296``` 297 298### createPhotoAsset 299 300createPhotoAsset(displayName: string, createOption: PhotoCreateOptions, callback: AsyncCallback<FileAsset>): void; 301 302Creates an image or video asset with the specified file name and options. This API uses an asynchronous callback to return the result. 303 304**System capability**: SystemCapability.FileManagement.UserFileManager.Core 305 306**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 307 308**Parameters** 309 310| Name | Type | Mandatory| Description | 311| -------- | ------------------------ | ---- | ------------------------- | 312| displayName | string | Yes | File name of the image or video to create. | 313| createOption | [PhotoCreateOptions](#photocreateoptions10) | Yes | Options for creating an image or video asset. | 314| callback | AsyncCallback<[FileAsset](#fileasset)> | Yes | Callback invoked to return the image or video created.| 315 316**Error codes** 317 318For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 319 320| ID| Error Message| 321| -------- | ---------------------------------------- | 322| 13900020 | if type displayName is not string. | 323| 14000001 | if type displayName invalid. | 324 325**Example** 326 327```ts 328async function example() { 329 console.info('createPhotoAssetDemo'); 330 let testFileName: string = 'testFile' + Date.now() + '.jpg'; 331 let createOption: userFileManager.PhotoCreateOptions = { 332 subType: userFileManager.PhotoSubType.DEFAULT 333 } 334 mgr.createPhotoAsset(testFileName, createOption, (err, fileAsset) => { 335 if (fileAsset != undefined) { 336 console.info('createPhotoAsset file displayName' + fileAsset.displayName); 337 console.info('createPhotoAsset successfully'); 338 } else { 339 console.error('createPhotoAsset failed, message = ', err); 340 } 341 }); 342} 343``` 344 345### createPhotoAsset 346 347createPhotoAsset(displayName: string, createOption: PhotoCreateOptions): Promise<FileAsset>; 348 349Creates an image or video asset with the specified file name and options. This API uses a promise to return the result. 350 351**System capability**: SystemCapability.FileManagement.UserFileManager.Core 352 353**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 354 355**Parameters** 356 357| Name | Type | Mandatory| Description | 358| -------- | ------------------------ | ---- | ------------------------- | 359| displayName | string | Yes | File name of the image or video to create. | 360| createOption | [PhotoCreateOptions](#photocreateoptions10) | Yes | Options for creating an image or video asset. | 361 362**Return value** 363 364| Type | Description | 365| --------------------------- | -------------- | 366| Promise<[FileAsset](#fileasset)> | Promise used to return the created image and video asset.| 367 368**Error codes** 369 370For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 371 372| ID| Error Message| 373| -------- | ---------------------------------------- | 374| 13900020 | if type displayName is not string. | 375 376**Example** 377 378```ts 379async function example() { 380 console.info('createPhotoAssetDemo'); 381 try { 382 let testFileName: string = 'testFile' + Date.now() + '.jpg'; 383 let createOption: userFileManager.PhotoCreateOptions = { 384 subType: userFileManager.PhotoSubType.DEFAULT 385 } 386 let fileAsset: userFileManager.FileAsset = await mgr.createPhotoAsset(testFileName, createOption); 387 console.info('createPhotoAsset file displayName' + fileAsset.displayName); 388 console.info('createPhotoAsset successfully'); 389 } catch (err) { 390 console.error('createPhotoAsset failed, message = ', err); 391 } 392} 393``` 394 395### createAudioAsset<sup>10+</sup> 396 397createAudioAsset(displayName: string, callback: AsyncCallback<FileAsset>): void; 398 399Creates an audio asset. This API uses an asynchronous callback to return the result. 400 401**System capability**: SystemCapability.FileManagement.UserFileManager.Core 402 403**Required permissions**: ohos.permission.WRITE_AUDIO 404 405**Parameters** 406 407| Name | Type | Mandatory| Description | 408| -------- | ------------------------ | ---- | ------------------------- | 409| displayName | string | Yes | File name of the audio asset to create. | 410| callback | AsyncCallback<[FileAsset](#fileasset)> | Yes | Callback invoked to return the created audio asset.| 411 412**Error codes** 413 414For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 415 416| ID| Error Message| 417| -------- | ---------------------------------------- | 418| 13900020 | if type displayName is not string. | 419| 14000001 | if type displayName invalid. | 420 421**Example** 422 423```ts 424async function example() { 425 console.info('createAudioAssetDemo'); 426 let testFileName: string = 'testFile' + Date.now() + '.mp3'; 427 mgr.createAudioAsset(testFileName, (err, fileAsset) => { 428 if (fileAsset != undefined) { 429 console.info('createAudioAsset file displayName' + fileAsset.displayName); 430 console.info('createAudioAsset successfully'); 431 } else { 432 console.error('createAudioAsset failed, message = ', err); 433 } 434 }); 435} 436``` 437 438### createAudioAsset<sup>10+</sup> 439 440createAudioAsset(displayName: string): Promise<FileAsset>; 441 442Creates an audio asset. This API uses a promise to return the result. 443 444**System capability**: SystemCapability.FileManagement.UserFileManager.Core 445 446**Required permissions**: ohos.permission.WRITE_AUDIO 447 448**Parameters** 449 450| Name | Type | Mandatory| Description | 451| -------- | ------------------------ | ---- | ------------------------- | 452| displayName | string | Yes | File name of the audio asset to create. | 453 454**Return value** 455 456| Type | Description | 457| --------------------------- | -------------- | 458| Promise<[FileAsset](#fileasset)> | Promise used to return the created audio asset.| 459 460**Error codes** 461 462For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 463 464| ID| Error Message| 465| -------- | ---------------------------------------- | 466| 13900020 | if type displayName is not string. | 467 468**Example** 469 470```ts 471async function example() { 472 console.info('createAudioAssetDemo'); 473 try { 474 let testFileName: string = 'testFile' + Date.now() + '.mp3'; 475 let fileAsset: userFileManager.FileAsset = await mgr.createAudioAsset(testFileName); 476 console.info('createAudioAsset file displayName' + fileAsset.displayName); 477 console.info('createAudioAsset successfully'); 478 } catch (err) { 479 console.error('createAudioAsset failed, message = ', err); 480 } 481} 482``` 483 484### createAlbum<sup>10+</sup> 485 486createAlbum(name: string, callback: AsyncCallback<Album>): void; 487 488Creates an album. This API uses an asynchronous callback to return the result. 489 490The album name must meet the following requirements: 491- The album name is a string of 1 to 255 characters. 492- The album name cannot contain any of the following characters:<br>.. \ / : * ? " ' ` < > | { } [ ] 493- The album name is case-insensitive. 494- Duplicate album names are not allowed. 495 496**System capability**: SystemCapability.FileManagement.UserFileManager.Core 497 498**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 499 500**Parameters** 501 502| Name | Type | Mandatory| Description | 503| -------- | ------------------------ | ---- | ------------------------- | 504| name | string | Yes | Name of the album to create. | 505| callback | AsyncCallback<[Album](#album)> | Yes | Callback invoked to return the created album instance.| 506 507**Example** 508 509```ts 510async function example() { 511 console.info('createAlbumDemo'); 512 let albumName: string = 'newAlbumName' + new Date().getTime(); 513 mgr.createAlbum(albumName, (err, album) => { 514 if (err) { 515 console.error('createAlbumCallback failed with err: ' + err); 516 return; 517 } 518 console.info('createAlbumCallback successfully, album: ' + album.albumName + ' album uri: ' + album.albumUri); 519 }); 520} 521``` 522 523### createAlbum<sup>10+</sup> 524 525createAlbum(name: string): Promise<Album>; 526 527Creates an album. This API uses a promise to return the result. 528 529The album name must meet the following requirements: 530- The album name is a string of 1 to 255 characters. 531- The album name cannot contain any of the following characters:<br>.. \ / : * ? " ' ` < > | { } [ ] 532- The album name is case-insensitive. 533- Duplicate album names are not allowed. 534 535**System capability**: SystemCapability.FileManagement.UserFileManager.Core 536 537**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 538 539**Parameters** 540 541| Name | Type | Mandatory| Description | 542| -------- | ------------------------ | ---- | ------------------------- | 543| name | string | Yes | Name of the album to create. | 544 545**Return value** 546 547| Type | Description | 548| --------------------------- | -------------- | 549| Promise<[Album](#album)> | Promise used to return the created album instance.| 550 551**Example** 552 553```ts 554import { BusinessError } from '@ohos.base'; 555 556async function example() { 557 console.info('createAlbumDemo'); 558 let albumName: string = 'newAlbumName' + new Date().getTime(); 559 mgr.createAlbum(albumName).then((album) => { 560 console.info('createAlbumPromise successfully, album: ' + album.albumName + ' album uri: ' + album.albumUri); 561 }).catch((err: BusinessError) => { 562 console.error('createAlbumPromise failed with err: ' + err); 563 }); 564} 565``` 566 567### deleteAlbums<sup>10+</sup> 568 569deleteAlbums(albums: Array<Album>, callback: AsyncCallback<void>): void; 570 571Deletes albums. This API uses an asynchronous callback to return the result. 572 573Ensure that the albums to be deleted exist. Only user albums can be deleted. 574 575**System capability**: SystemCapability.FileManagement.UserFileManager.Core 576 577**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 578 579**Parameters** 580 581| Name | Type | Mandatory| Description | 582| -------- | ------------------------ | ---- | ------------------------- | 583| albums | Array<[Album](#album)> | Yes | Albums to delete. | 584| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 585 586**Example** 587 588```ts 589import dataSharePredicates from '@ohos.data.dataSharePredicates'; 590 591async function example() { 592 // Delete the album named newAlbumName. 593 console.info('deleteAlbumsDemo'); 594 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 595 predicates.equalTo('album_name', 'newAlbumName'); 596 let fetchOptions: userFileManager.FetchOptions = { 597 fetchColumns: [], 598 predicates: predicates 599 }; 600 let fetchResult: userFileManager.FetchResult<userFileManager.Album> = await mgr.getAlbums(userFileManager.AlbumType.USER, userFileManager.AlbumSubType.USER_GENERIC, fetchOptions); 601 let album: userFileManager.Album = await fetchResult.getFirstObject(); 602 mgr.deleteAlbums([album], (err) => { 603 if (err) { 604 console.error('deletePhotoAlbumsCallback failed with err: ' + err); 605 return; 606 } 607 console.info('deletePhotoAlbumsCallback successfully'); 608 }); 609 fetchResult.close(); 610} 611``` 612 613### deleteAlbums<sup>10+</sup> 614 615deleteAlbums(albums: Array<Album>): Promise<void>; 616 617Deletes albums. This API uses a promise to return the result. 618 619Ensure that the albums to be deleted exist. Only user albums can be deleted. 620 621**System capability**: SystemCapability.FileManagement.UserFileManager.Core 622 623**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 624 625**Parameters** 626 627| Name | Type | Mandatory| Description | 628| -------- | ------------------------ | ---- | ------------------------- | 629| albums | Array<[Album](#album)> | Yes | Albums to delete. | 630 631**Return value** 632 633| Type | Description | 634| --------------------------- | -------------- | 635| Promise<void> | Promise that returns no value.| 636 637**Example** 638 639```ts 640import dataSharePredicates from '@ohos.data.dataSharePredicates'; 641import { BusinessError } from '@ohos.base'; 642 643async function example() { 644 // Delete the album named newAlbumName. 645 console.info('deleteAlbumsDemo'); 646 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 647 predicates.equalTo('album_name', 'newAlbumName'); 648 let fetchOptions: userFileManager.FetchOptions = { 649 fetchColumns: [], 650 predicates: predicates 651 }; 652 let fetchResult: userFileManager.FetchResult<userFileManager.Album> = await mgr.getAlbums(userFileManager.AlbumType.USER, userFileManager.AlbumSubType.USER_GENERIC, fetchOptions); 653 let album: userFileManager.Album = await fetchResult.getFirstObject(); 654 mgr.deleteAlbums([album]).then(() => { 655 console.info('deletePhotoAlbumsPromise successfully'); 656 }).catch((err: BusinessError) => { 657 console.error('deletePhotoAlbumsPromise failed with err: ' + err); 658 }); 659 fetchResult.close(); 660} 661``` 662 663### getAlbums<sup>10+</sup> 664 665getAlbums(type: AlbumType, subType: AlbumSubType, options: FetchOptions, callback: AsyncCallback<FetchResult<Album>>): void; 666 667Obtain albums based on the specified options and album type. This API uses an asynchronous callback to return the result. 668 669Before the operation, ensure that the albums to obtain exist. 670 671**System capability**: SystemCapability.FileManagement.UserFileManager.Core 672 673**Required permissions**: ohos.permission.READ_IMAGEVIDEO 674 675**Parameters** 676 677| Name | Type | Mandatory| Description | 678| -------- | ------------------------ | ---- | ------------------------- | 679| type | [AlbumType](#albumtype10) | Yes | Type of the album to obtain. | 680| subType | [AlbumSubType](#albumsubtype10) | Yes | Subtype of the album. | 681| options | [FetchOptions](#fetchoptions) | Yes | Options for fetching the albums. | 682| callback | AsyncCallback<[FetchResult](#fetchresult)<[Album](#album)>> | Yes | Callback invoked to return the result.| 683 684**Error codes** 685 686For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 687 688| ID| Error Message| 689| -------- | ---------------------------------------- | 690| 13900020 | if type options is not FetchOption. | 691 692**Example** 693 694```ts 695import dataSharePredicates from '@ohos.data.dataSharePredicates'; 696 697async function example() { 698 // Obtain the album named newAlbumName. 699 console.info('getAlbumsDemo'); 700 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 701 predicates.equalTo('album_name', 'newAlbumName'); 702 let fetchOptions: userFileManager.FetchOptions = { 703 fetchColumns: [], 704 predicates: predicates 705 }; 706 mgr.getAlbums(userFileManager.AlbumType.USER, userFileManager.AlbumSubType.USER_GENERIC, fetchOptions, async (err, fetchResult) => { 707 if (err) { 708 console.error('getAlbumsCallback failed with err: ' + err); 709 return; 710 } 711 if (fetchResult == undefined) { 712 console.error('getAlbumsCallback fetchResult is undefined'); 713 return; 714 } 715 let album: userFileManager.Album = await fetchResult.getFirstObject(); 716 console.info('getAlbumsCallback successfully, albumName: ' + album.albumName); 717 fetchResult.close(); 718 }); 719} 720``` 721 722### getAlbums<sup>10+</sup> 723 724getAlbums(type: AlbumType, subType: AlbumSubType, callback: AsyncCallback<FetchResult<Album>>): void; 725 726Obtains albums by type. This API uses an asynchronous callback to return the result. 727 728Before the operation, ensure that the albums to obtain exist. 729 730**System capability**: SystemCapability.FileManagement.UserFileManager.Core 731 732**Required permissions**: ohos.permission.READ_IMAGEVIDEO 733 734**Parameters** 735 736| Name | Type | Mandatory| Description | 737| -------- | ------------------------ | ---- | ------------------------- | 738| type | [AlbumType](#albumtype10) | Yes | Type of the album to obtain. | 739| subType | [AlbumSubType](#albumsubtype10) | Yes | Subtype of the album. | 740| callback | AsyncCallback<[FetchResult](#fetchresult)<[Album](#album)>> | Yes | Callback invoked to return the result.| 741 742**Error codes** 743 744For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 745 746| ID| Error Message| 747| -------- | ---------------------------------------- | 748| 13900020 | if type options is not FetchOption. | 749 750**Example** 751 752```ts 753async function example() { 754 // Obtain the system album VIDEO, which is preset by default. 755 console.info('getAlbumsDemo'); 756 mgr.getAlbums(userFileManager.AlbumType.SYSTEM, userFileManager.AlbumSubType.VIDEO, async (err, fetchResult) => { 757 if (err) { 758 console.error('getAlbumsCallback failed with err: ' + err); 759 return; 760 } 761 if (fetchResult == undefined) { 762 console.error('getAlbumsCallback fetchResult is undefined'); 763 return; 764 } 765 let album: userFileManager.Album = await fetchResult.getFirstObject(); 766 console.info('getAlbumsCallback successfully, albumUri: ' + album.albumUri); 767 fetchResult.close(); 768 }); 769} 770``` 771 772### getAlbums<sup>10+</sup> 773 774getAlbums(type: AlbumType, subType: AlbumSubType, options?: FetchOptions): Promise<FetchResult<Album>>; 775 776Obtain albums based on the specified options and album type. This API uses a promise to return the result. 777 778Before the operation, ensure that the albums to obtain exist. 779 780**System capability**: SystemCapability.FileManagement.UserFileManager.Core 781 782**Required permissions**: ohos.permission.READ_IMAGEVIDEO 783 784**Parameters** 785 786| Name | Type | Mandatory| Description | 787| -------- | ------------------------ | ---- | ------------------------- | 788| type | [AlbumType](#albumtype10) | Yes | Type of the album to obtain. | 789| subType | [AlbumSubType](#albumsubtype10) | Yes | Subtype of the album. | 790| 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. | 791 792**Return value** 793 794| Type | Description | 795| --------------------------- | -------------- | 796| Promise<[FetchResult](#fetchresult)<[Album](#album)>> | Promise used to return the result.| 797 798**Error codes** 799 800For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 801 802| ID| Error Message| 803| -------- | ---------------------------------------- | 804| 13900020 | if type options is not FetchOption. | 805 806**Example** 807 808```ts 809import dataSharePredicates from '@ohos.data.dataSharePredicates'; 810import { BusinessError } from '@ohos.base'; 811 812async function example() { 813 // Obtain the album named newAlbumName. 814 console.info('getAlbumsDemo'); 815 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 816 predicates.equalTo('album_name', 'newAlbumName'); 817 let fetchOptions: userFileManager.FetchOptions = { 818 fetchColumns: [], 819 predicates: predicates 820 }; 821 mgr.getAlbums(userFileManager.AlbumType.USER, userFileManager.AlbumSubType.USER_GENERIC, fetchOptions).then( async (fetchResult) => { 822 if (fetchResult == undefined) { 823 console.error('getAlbumsPromise fetchResult is undefined'); 824 return; 825 } 826 let album: userFileManager.Album = await fetchResult.getFirstObject(); 827 console.info('getAlbumsPromise successfully, albumName: ' + album.albumName); 828 fetchResult.close(); 829 }).catch((err: BusinessError) => { 830 console.error('getAlbumsPromise failed with err: ' + err); 831 }); 832} 833``` 834 835### getPhotoAlbums 836 837getPhotoAlbums(options: AlbumFetchOptions, callback: AsyncCallback<FetchResult<Album>>): void; 838 839Obtains image and video albums. This API uses an asynchronous callback to return the result. 840 841This API will be deprecated. Use [getAlbums<sup>10+</sup>](#getalbums10) instead. 842 843**System capability**: SystemCapability.FileManagement.UserFileManager.Core 844 845**Required permissions**: ohos.permission.READ_IMAGEVIDEO 846 847**Parameters** 848 849| Name | Type | Mandatory| Description | 850| -------- | ------------------------ | ---- | ------------------------- | 851| options | [AlbumFetchOptions](#albumfetchoptions) | Yes | Options for fetching the albums. | 852| callback | AsyncCallback<[FetchResult](#fetchresult)<[Album](#album)>> | Yes | Callback invoked to return the image and video albums obtained.| 853 854**Error codes** 855 856For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 857 858| ID| Error Message| 859| -------- | ---------------------------------------- | 860| 13900020 | if type options is not AlbumFetchOptions. | 861 862**Example** 863 864```ts 865import dataSharePredicates from '@ohos.data.dataSharePredicates'; 866 867async function example() { 868 console.info('getPhotoAlbumsDemo'); 869 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 870 let albumFetchOptions: userFileManager.AlbumFetchOptions = { 871 predicates: predicates 872 }; 873 874 mgr.getPhotoAlbums(albumFetchOptions, (err, fetchResult) => { 875 if (fetchResult != undefined) { 876 console.info('albums.count = ' + fetchResult.getCount()); 877 fetchResult.getFirstObject((err, album) => { 878 if (album != undefined) { 879 console.info('first album.albumName = ' + album.albumName); 880 } else { 881 console.error('album is undefined, err = ', err); 882 } 883 }); 884 } else { 885 console.error('getPhotoAlbums fail, message = ', err); 886 } 887 }); 888} 889``` 890 891### getPhotoAlbums 892 893getPhotoAlbums(options: AlbumFetchOptions): Promise<FetchResult<Album>>; 894 895Obtains image and video albums. This API uses a promise to return the result. 896 897This API will be deprecated. Use [getAlbums<sup>10+</sup>](#getalbums10) instead. 898 899**System capability**: SystemCapability.FileManagement.UserFileManager.Core 900 901**Required permissions**: ohos.permission.READ_IMAGEVIDEO 902 903**Parameters** 904 905| Name | Type | Mandatory| Description | 906| -------- | ------------------------ | ---- | ------------------------- | 907| options | [AlbumFetchOptions](#albumfetchoptions) | Yes | Options for fetching the albums. | 908 909**Return value** 910 911| Type | Description | 912| --------------------------- | -------------- | 913| Promise<[FetchResult](#fetchresult)<[Album](#album)>> | Promise used to return the image and video albums obtained.| 914 915**Error codes** 916 917For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 918 919| ID| Error Message| 920| -------- | ---------------------------------------- | 921| 13900020 | if type options is not AlbumFetchOptions. | 922 923**Example** 924 925```ts 926import dataSharePredicates from '@ohos.data.dataSharePredicates'; 927 928async function example() { 929 console.info('getPhotoAlbumsDemo'); 930 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 931 let albumFetchOptions: userFileManager.AlbumFetchOptions = { 932 predicates: predicates 933 }; 934 try { 935 let fetchResult: userFileManager.FetchResult<userFileManager.Album> = await mgr.getPhotoAlbums(albumFetchOptions); 936 console.info('album.count = ' + fetchResult.getCount()); 937 const album: userFileManager.Album = await fetchResult.getFirstObject(); 938 console.info('first album.albumName = ' + album.albumName); 939 } catch (err) { 940 console.error('getPhotoAlbums fail, message = ' + err); 941 } 942} 943``` 944 945### getPrivateAlbum 946 947getPrivateAlbum(type: PrivateAlbumType, callback: AsyncCallback<FetchResult<PrivateAlbum>>): void; 948 949Obtains the system album. This API uses an asynchronous callback to return the result. 950 951This API will be deprecated. Use [getAlbums<sup>10+</sup>](#getalbums10) instead. 952 953**System capability**: SystemCapability.FileManagement.UserFileManager.Core 954 955**Required permissions**: ohos.permission.READ_IMAGEVIDEO 956 957**Parameters** 958 959| Name | Type | Mandatory| Description | 960| -------- | ------------------------ | ---- | ------------------------- | 961| type | [PrivateAlbumType](#privatealbumtype) | Yes | Type of the system album to obtain. | 962| callback | AsyncCallback<[FetchResult](#fetchresult)<[PrivateAlbum](#privatealbum)>> | Yes | Callback invoked to return the album obtained.| 963 964**Error codes** 965 966For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 967 968| ID| Error Message| 969| -------- | ---------------------------------------- | 970| 13900020 | if type type is not PrivateAlbumType. | 971 972**Example** 973 974```ts 975async function example() { 976 console.info('getPrivateAlbumDemo'); 977 mgr.getPrivateAlbum(userFileManager.PrivateAlbumType.TYPE_TRASH, async (err, fetchResult) => { 978 if (fetchResult != undefined) { 979 let trashAlbum: userFileManager.PrivateAlbum = await fetchResult.getFirstObject(); 980 console.info('first album.albumName = ' + trashAlbum.albumName); 981 } else { 982 console.error('getPrivateAlbum failed. message = ', err); 983 } 984 }); 985} 986``` 987 988### getPrivateAlbum 989 990getPrivateAlbum(type: PrivateAlbumType): Promise<FetchResult<PrivateAlbum>>; 991 992Obtains the system album. This API uses a promise to return the result. 993 994This API will be deprecated. Use [getAlbums<sup>10+</sup>](#getalbums10) instead. 995 996**System capability**: SystemCapability.FileManagement.UserFileManager.Core 997 998**Required permissions**: ohos.permission.READ_IMAGEVIDEO 999 1000**Parameters** 1001 1002| Name | Type | Mandatory| Description | 1003| -------- | ------------------------ | ---- | ------------------------- | 1004| type | [PrivateAlbumType](#privatealbumtype) | Yes | Type of the system album to obtain. | 1005 1006**Return value** 1007 1008| Type | Description | 1009| --------------------------- | -------------- | 1010| Promise<[FetchResult](#fetchresult)<[PrivateAlbum](#privatealbum)>> | Promise used to return the system album obtained.| 1011 1012**Error codes** 1013 1014For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 1015 1016| ID| Error Message| 1017| -------- | ---------------------------------------- | 1018| 13900020 | if type type is not PrivateAlbumType. | 1019 1020**Example** 1021 1022```ts 1023async function example() { 1024 console.info('getPrivateAlbumDemo'); 1025 try { 1026 let fetchResult: userFileManager.FetchResult<userFileManager.PrivateAlbum> = await mgr.getPrivateAlbum(userFileManager.PrivateAlbumType.TYPE_TRASH); 1027 let trashAlbum: userFileManager.PrivateAlbum = await fetchResult.getFirstObject(); 1028 console.info('first album.albumName = ' + trashAlbum.albumName); 1029 } catch (err) { 1030 console.error('getPrivateAlbum failed. message = ', err); 1031 } 1032} 1033``` 1034 1035### getAudioAssets 1036 1037getAudioAssets(options: FetchOptions, callback: AsyncCallback<FetchResult<FileAsset>>): void; 1038 1039Obtains audio assets. This API uses an asynchronous callback to return the result. 1040 1041**System capability**: SystemCapability.FileManagement.UserFileManager.Core 1042 1043**Required permissions**: ohos.permission.READ_AUDIO 1044 1045**Parameters** 1046 1047| Name | Type | Mandatory| Description | 1048| -------- | ------------------------ | ---- | ------------------------- | 1049| options | [FetchOptions](#fetchoptions) | Yes | Options for fetching the audio assets. | 1050| callback | AsyncCallback<[FetchResult](#fetchresult)<[FileAsset](#fileasset)>> | Yes | Callback invoked to return the audio assets obtained.| 1051 1052**Error codes** 1053 1054For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 1055 1056| ID| Error Message| 1057| -------- | ---------------------------------------- | 1058| 13900020 | if type options is not FetchOptions. | 1059 1060**Example** 1061 1062```ts 1063import dataSharePredicates from '@ohos.data.dataSharePredicates'; 1064 1065async function example() { 1066 console.info('getAudioAssets'); 1067 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1068 let fetchOptions: userFileManager.FetchOptions = { 1069 fetchColumns: [], 1070 predicates: predicates 1071 }; 1072 1073 mgr.getAudioAssets(fetchOptions, async (err, fetchResult) => { 1074 if (fetchResult != undefined) { 1075 console.info('fetchFileResult success'); 1076 let fileAsset: userFileManager.FileAsset = await fetchResult.getFirstObject(); 1077 if (fileAsset != undefined) { 1078 console.info('fileAsset.displayName :' + fileAsset.displayName); 1079 } 1080 } else { 1081 console.error('fetchFileResult fail' + err); 1082 } 1083 }); 1084} 1085``` 1086 1087### getAudioAssets 1088 1089getAudioAssets(options: FetchOptions): Promise<FetchResult<FileAsset>>; 1090 1091 1092Obtains audio assets. This API uses a promise to return the result. 1093 1094**System capability**: SystemCapability.FileManagement.UserFileManager.Core 1095 1096**Required permissions**: ohos.permission.READ_AUDIO 1097 1098**Parameters** 1099 1100| Name | Type | Mandatory| Description | 1101| -------- | ------------------------ | ---- | ------------------------- | 1102| options | [FetchOptions](#fetchoptions) | Yes | Options for fetching the audio assets. | 1103 1104**Return value** 1105 1106| Type | Description | 1107| --------------------------- | -------------- | 1108| Promise<[FetchResult](#fetchresult)<[FileAsset](#fileasset)>> | Promise used to return the audio assets obtained.| 1109 1110**Error codes** 1111 1112For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 1113 1114| ID| Error Message| 1115| -------- | ---------------------------------------- | 1116| 13900020 | if type options is not FetchOptions. | 1117 1118**Example** 1119 1120```ts 1121import dataSharePredicates from '@ohos.data.dataSharePredicates'; 1122 1123async function example() { 1124 console.info('getAudioAssets'); 1125 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1126 let fetchOptions: userFileManager.FetchOptions = { 1127 fetchColumns: [], 1128 predicates: predicates 1129 }; 1130 try { 1131 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await mgr.getAudioAssets(fetchOptions); 1132 if (fetchResult != undefined) { 1133 console.info('fetchFileResult success'); 1134 let fileAsset: userFileManager.FileAsset = await fetchResult.getFirstObject(); 1135 if (fileAsset != undefined) { 1136 console.info('fileAsset.displayName :' + fileAsset.displayName); 1137 } 1138 } 1139 } catch (err) { 1140 console.error('getAudioAssets failed, message = ', err); 1141 } 1142} 1143``` 1144 1145### delete 1146 1147delete(uri: string, callback: AsyncCallback<void>): void; 1148 1149Deletes a media file. This API uses an asynchronous callback to return the result. The deleted file is moved to the recycle bin. 1150 1151**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.READ_AUDIO, and ohos.permission.WRITE_AUDIO 1152 1153**System capability**: SystemCapability.FileManagement.UserFileManager.Core 1154 1155**Parameters** 1156 1157| Name | Type | Mandatory| Description | 1158| -------- | ------------------------- | ---- | ---------- | 1159| uri | string | Yes | URI of the media file.| 1160| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 1161 1162**Error codes** 1163 1164For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 1165 1166| ID| Error Message| 1167| -------- | ---------------------------------------- | 1168| 13900020 | if type uri is not string. | 1169 1170**Example** 1171 1172```ts 1173import dataSharePredicates from '@ohos.data.dataSharePredicates'; 1174 1175async function example() { 1176 console.info('deleteAssetDemo'); 1177 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1178 let fetchOptions: userFileManager.FetchOptions = { 1179 fetchColumns: [], 1180 predicates: predicates 1181 }; 1182 try { 1183 const fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await mgr.getPhotoAssets(fetchOptions); 1184 let asset: userFileManager.FileAsset = await fetchResult.getFirstObject(); 1185 1186 1187 if (asset == undefined) { 1188 console.error('asset not exist'); 1189 return; 1190 } 1191 mgr.delete(asset.uri, (err) => { 1192 if (err == undefined) { 1193 console.info('delete successfully'); 1194 } else { 1195 console.error('delete failed with error: ' + err); 1196 } 1197 }); 1198 } catch (err) { 1199 console.info('fetch failed, message =', err); 1200 } 1201} 1202``` 1203 1204### delete 1205 1206delete(uri: string): Promise<void>; 1207 1208Deletes a media file. This API uses a promise to return the result. The deleted file is moved to the recycle bin. 1209 1210**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.READ_AUDIO, and ohos.permission.WRITE_AUDIO 1211 1212**System capability**: SystemCapability.FileManagement.UserFileManager.Core 1213 1214**Parameters** 1215 1216| Name | Type | Mandatory| Description | 1217| -------- | ------------------------- | ---- | ---------- | 1218| uri | string | Yes | URI of the media file.| 1219 1220**Return value** 1221 1222| Type | Description | 1223| --------------------------------------- | ----------------- | 1224| Promise<void>| Promise that returns no value.| 1225 1226**Error codes** 1227 1228For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 1229 1230| ID| Error Message| 1231| -------- | ---------------------------------------- | 1232| 13900020 | if type uri is not string. | 1233 1234**Example** 1235 1236```ts 1237import dataSharePredicates from '@ohos.data.dataSharePredicates'; 1238 1239async function example() { 1240 console.info('deleteDemo'); 1241 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1242 let fetchOptions: userFileManager.FetchOptions = { 1243 fetchColumns: [], 1244 predicates: predicates 1245 }; 1246 try { 1247 const fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await mgr.getPhotoAssets(fetchOptions); 1248 let asset: userFileManager.FileAsset = await fetchResult.getFirstObject(); 1249 if (asset == undefined) { 1250 console.error('asset not exist'); 1251 return; 1252 } 1253 await mgr.delete(asset.uri); 1254 console.info('delete successfully'); 1255 } catch (err) { 1256 console.error('delete failed with error: ' + err); 1257 } 1258} 1259``` 1260 1261### getActivePeers 1262 1263getActivePeers(callback: AsyncCallback<Array<PeerInfo>>): void; 1264 1265Obtains information about online peer devices. This API uses an asynchronous callback to return the result. 1266 1267**System capability**: SystemCapability.FileManagement.UserFileManager.DistributedCore 1268 1269**Parameters** 1270 1271| Name | Type | Mandatory| Description | 1272| -------- | --------------------------------- | ---- | ------------ | 1273| callback | AsyncCallback<Array<[PeerInfo](#peerinfo)>> | Yes | Callback invoked to return a list of online peer devices.| 1274 1275**Example** 1276 1277```ts 1278async function example() { 1279 console.info('getActivePeersDemo'); 1280 mgr.getActivePeers((err, devicesInfo) => { 1281 if (devicesInfo != undefined) { 1282 console.log('getActivePeers succeed.'); 1283 for (let i = 0; i < devicesInfo.length; i++) { 1284 console.info('get distributed info ' + devicesInfo[i].deviceName + devicesInfo[i].networkId); 1285 } 1286 } else { 1287 console.error('getActivePeers failed. message = ', err); 1288 } 1289 }); 1290} 1291``` 1292 1293### getActivePeers 1294 1295getActivePeers(): Promise<Array<PeerInfo>>; 1296 1297Obtains information about online peer devices. This API uses a promise to return the result. 1298 1299**System capability**: SystemCapability.FileManagement.UserFileManager.DistributedCore 1300 1301**Return value** 1302 1303| Type | Description | 1304| --------------------------- | ----------------------------- | 1305| Promise<Array<[PeerInfo](#peerinfo)>> | Promise used to return a list of online peer devices.| 1306 1307**Example** 1308 1309```ts 1310async function example() { 1311 console.info('getActivePeersDemo'); 1312 try { 1313 let devicesInfo: Array<userFileManager.PeerInfo> = await mgr.getActivePeers(); 1314 if (devicesInfo != undefined) { 1315 console.log('getActivePeers succeed.'); 1316 for (let i = 0; i < devicesInfo.length; i++) { 1317 console.info('get distributed info ' + devicesInfo[i].deviceName + devicesInfo[i].networkId); 1318 } 1319 } else { 1320 console.error('get distributed fail'); 1321 } 1322 } catch (err) { 1323 console.error('getActivePeers failed. message = ', err); 1324 } 1325} 1326``` 1327 1328### getAllPeers 1329 1330getAllPeers(callback: AsyncCallback<Array<PeerInfo>>): void; 1331 1332Obtains information about all peer devices. This API uses an asynchronous callback to return the result. 1333 1334**System capability**: SystemCapability.FileManagement.UserFileManager.DistributedCore 1335 1336**Parameters** 1337 1338| Name | Type | Mandatory| Description | 1339| -------- | --------------------------------- | ---- | ------------ | 1340| callback | AsyncCallback<Array<[PeerInfo](#peerinfo)>> | Yes | Callback invoked to return the peer device information obtained.| 1341 1342**Example** 1343 1344```ts 1345async function example() { 1346 console.info('getAllPeersDemo'); 1347 mgr.getAllPeers((err, devicesInfo) => { 1348 if (devicesInfo != undefined) { 1349 console.log('getAllPeers succeed.'); 1350 for (let i = 0; i < devicesInfo.length; i++) { 1351 console.info('get distributed info ' + devicesInfo[i].deviceName + devicesInfo[i].networkId); 1352 } 1353 } else { 1354 console.error('getAllPeers failed. message = ', err); 1355 } 1356 }); 1357} 1358``` 1359 1360### getAllPeers 1361 1362getAllPeers(): Promise<Array<PeerInfo>>; 1363 1364Obtains information about all peer devices. This API uses a promise to return the result. 1365 1366**System capability**: SystemCapability.FileManagement.UserFileManager.DistributedCore 1367 1368**Return value** 1369 1370| Type | Description | 1371| --------------------------- | ----------------------------- | 1372| Promise<Array<[PeerInfo](#peerinfo)>> | Promise used to return the information obtained.| 1373 1374**Example** 1375 1376```ts 1377async function example() { 1378 console.info('getAllPeersDemo'); 1379 try { 1380 let devicesInfo: Array<userFileManager.PeerInfo> = await mgr.getAllPeers(); 1381 1382 if (devicesInfo != undefined) { 1383 console.log('getAllPeers succeed.'); 1384 for (let i = 0; i < devicesInfo.length; i++) { 1385 console.info('get distributed info ' + devicesInfo[i].deviceName + devicesInfo[i].networkId); 1386 } 1387 } else { 1388 console.error('get distributed fail'); 1389 } 1390 } catch (err) { 1391 console.error('getAllPeers failed. message = ', err); 1392 } 1393} 1394``` 1395 1396### getPhotoIndex<sup>10+</sup> 1397 1398getPhotoIndex(photoUri: string, albumUri: string, options: FetchOptions, callback: AsyncCallback<number>): void 1399 1400Obtains the index of an image or video in an album. This API uses an asynchronous callback to return the result. 1401 1402**System API**: This is a system API. 1403 1404**Required permissions**: ohos.permission.READ_IMAGEVIDEO 1405 1406**System capability**: SystemCapability.FileManagement.UserFileManager.Core 1407 1408**Parameters** 1409 1410| Name | Type | Mandatory| Description | 1411| -------- | ------------------------- | ---- | ---------- | 1412| photoUri | string | Yes | URI of the media asset whose index is to be obtained.| 1413| albumUri | string | Yes | Album URI, which can be an empty string. If it is an empty string, all the media assets in the Gallery are obtained by default. | 1414| options | [FetchOptions](#fetchoptions) | Yes | Fetch options. Only one search condition or sorting mode must be set in **predicates**. If no value is set or multiple search conditions or sorting modes are set, the API cannot be called successfully. | 1415 1416**Return value** 1417 1418| Type | Description | 1419| --------------------------------------- | ----------------- | 1420| AsyncCallback<number>| Callback invoked to return the index obtained.| 1421 1422**Error codes** 1423 1424For details about the error codes, see [Universal Error Codes](../errorcodes/errorcode-universal.md). 1425 1426| ID| Error Message| 1427| -------- | ---------------------------------------- | 1428| 401 | if parameter is invalid. | 1429 1430**Example** 1431 1432```ts 1433import dataSharePredicates from '@ohos.data.dataSharePredicates'; 1434 1435async function example() { 1436 try { 1437 console.info('getPhotoIndexDemo'); 1438 let predicatesForGetAsset: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1439 let fetchOp: userFileManager.FetchOptions = { 1440 fetchColumns: [], 1441 predicates: predicatesForGetAsset 1442 }; 1443 // Obtain the uri of the album 1444 let albumFetchResult: userFileManager.FetchResult<userFileManager.Album> = await mgr.getAlbums(userFileManager.AlbumType.SYSTEM, userFileManager.AlbumSubType.FAVORITE, fetchOp); 1445 let album: userFileManager.Album = await albumFetchResult.getFirstObject(); 1446 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1447 predicates.orderByAsc(userFileManager.ImageVideoKey.DATE_MODIFIED.toString()); 1448 let fetchOptions: userFileManager.FetchOptions = { 1449 fetchColumns: [userFileManager.ImageVideoKey.DATE_MODIFIED.toString()], 1450 predicates: predicates 1451 }; 1452 let photoFetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await album.getPhotoAssets(fetchOptions); 1453 let expectIndex = 1; 1454 // Obtain the uri of the second file 1455 let photoAsset: userFileManager.FileAsset = await photoFetchResult.getPositionObject(expectIndex); 1456 mgr.getPhotoIndex(photoAsset.uri, album.albumUri, fetchOptions, (err, index) => { 1457 if (err == undefined) { 1458 console.info(`getPhotoIndex successfully and index is : ${index}`); 1459 } else { 1460 console.info(`getPhotoIndex failed;`); 1461 } 1462 }); 1463 } catch (error) { 1464 console.info(`getPhotoIndex failed; error: ${error}`); 1465 } 1466} 1467``` 1468 1469### getPhotoIndex<sup>10+</sup> 1470 1471getPhotoIndex(photoUri: string, albumUri: string, options: FetchOptions): Promise<number> 1472 1473Obtains the index of an image or video in an album. This API uses a promise to return the result. 1474 1475**System API**: This is a system API. 1476 1477**Required permissions**: ohos.permission.READ_IMAGEVIDEO 1478 1479**System capability**: SystemCapability.FileManagement.UserFileManager.Core 1480 1481**Parameters** 1482 1483| Name | Type | Mandatory| Description | 1484| -------- | ------------------------- | ---- | ---------- | 1485| photoUri | string | Yes | URI of the media asset whose index is to be obtained.| 1486| albumUri | string | Yes | Album URI, which can be an empty string. If it is an empty string, all the media assets in the Gallery are obtained by default. | 1487| options | [FetchOptions](#fetchoptions) | Yes | Fetch options. Only one search condition or sorting mode must be set in **predicates**. If no value is set or multiple search conditions or sorting modes are set, the API cannot be called successfully. | 1488 1489**Return value** 1490 1491| Type | Description | 1492| --------------------------------------- | ----------------- | 1493| Promise<number>| Promise used to return the index obtained.| 1494 1495**Error codes** 1496 1497For details about the error codes, see [Universal Error Codes](../errorcodes/errorcode-universal.md). 1498 1499| ID| Error Message| 1500| -------- | ---------------------------------------- | 1501| 401 | if parameter is invalid. | 1502 1503**Example** 1504 1505```ts 1506import dataSharePredicates from '@ohos.data.dataSharePredicates'; 1507import { BusinessError } from '@ohos.base'; 1508 1509async function example() { 1510 try { 1511 console.info('getPhotoIndexDemo'); 1512 let predicatesForGetAsset: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1513 let fetchOp: userFileManager.FetchOptions = { 1514 fetchColumns: [], 1515 predicates: predicatesForGetAsset 1516 }; 1517 // Obtain the uri of the album 1518 let albumFetchResult: userFileManager.FetchResult<userFileManager.Album> = await mgr.getAlbums(userFileManager.AlbumType.SYSTEM, userFileManager.AlbumSubType.FAVORITE, fetchOp); 1519 let album: userFileManager.Album = await albumFetchResult.getFirstObject(); 1520 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1521 predicates.orderByAsc(userFileManager.ImageVideoKey.DATE_MODIFIED.toString()); 1522 let fetchOptions: userFileManager.FetchOptions = { 1523 fetchColumns: [userFileManager.ImageVideoKey.DATE_MODIFIED.toString()], 1524 predicates: predicates 1525 }; 1526 let photoFetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await album.getPhotoAssets(fetchOptions); 1527 let expectIndex = 1; 1528 // Obtain the uri of the second file 1529 let photoAsset: userFileManager.FileAsset = await photoFetchResult.getPositionObject(expectIndex); 1530 mgr.getPhotoIndex(photoAsset.uri, album.albumUri, fetchOptions).then((index) => { 1531 console.info(`getPhotoIndex successfully and index is : ${index}`); 1532 }).catch((err: BusinessError) => { 1533 console.info(`getPhotoIndex failed; error: ${err}`); 1534 }); 1535 } catch (error) { 1536 console.info(`getPhotoIndex failed; error: ${error}`); 1537 } 1538} 1539``` 1540 1541### release 1542 1543release(callback: AsyncCallback<void>): void 1544 1545Releases this **UserFileManager** instance. This API uses an asynchronous callback to return the result. 1546Call this API when the APIs in the **UserFileManager** instance are no longer used. 1547 1548**System capability**: SystemCapability.FileManagement.UserFileManager.Core 1549 1550**Parameters** 1551 1552| Name | Type | Mandatory| Description | 1553| -------- | ------------------------- | ---- | -------------------- | 1554| callback | AsyncCallback<void> | Yes | Callback invoked to return the result.| 1555 1556**Example** 1557 1558```ts 1559async function example() { 1560 console.info('releaseDemo'); 1561 mgr.release((err) => { 1562 if (err != undefined) { 1563 console.error('release failed. message = ', err); 1564 } else { 1565 console.info('release ok.'); 1566 } 1567 }); 1568} 1569``` 1570 1571### release 1572 1573release(): Promise<void> 1574 1575Releases this **UserFileManager** instance. This API uses a promise to return the result. 1576Call this API when the APIs in the **UserFileManager** instance are no longer used. 1577 1578**System capability**: SystemCapability.FileManagement.UserFileManager.Core 1579 1580**Return value** 1581 1582| Type | Description | 1583| ------------------- | --------------------------------- | 1584| Promise<void> | Promise that returns no value.| 1585 1586**Example** 1587 1588```ts 1589async function example() { 1590 console.info('releaseDemo'); 1591 try { 1592 await mgr.release(); 1593 console.info('release ok.'); 1594 } catch (err) { 1595 console.error('release failed. message = ', err); 1596 } 1597} 1598``` 1599 1600### on<sup>10+</sup> 1601 1602on(uri: string, forSubUri: boolean, callback: Callback<ChangeData>) : void 1603 1604Registers a listener for the specified URI. 1605 1606**System capability**: SystemCapability.FileManagement.UserFileManager.Core 1607 1608**Parameters** 1609 1610| Name | Type | Mandatory| Description | 1611| --------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | 1612| uri | string | Yes | URI of the file asset or album, or [DefaultChangeUri](#defaultchangeuri10).| 1613| forSubUri | boolean | Yes | Whether to perform fuzzy listening.<br>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. <br>If **uri** is the URI of a file asset, there is no difference between **true** and **false** for **forSubUri**.<br>If **uri** is **DefaultChangeUri**, **forSubUri** must be set to **true**. If **forSubUri** is **false**, the URI cannot be found and no message can be received.| 1614| callback | Callback<[ChangeData](#changedata10)> | Yes | Callback invoked to return [ChangeData](#changedata10). <br>**NOTE**: Different callbacks can be registered for a URI. You can use [off<sup>10+</sup>](#off10) to disable the specified callback or all callbacks for the URI.| 1615 1616**Error codes** 1617 1618For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 1619 1620| ID| Error Message| 1621| -------- | ---------------------------------------- | 1622| 13900020 | if parameter is invalid. | 1623 1624**Example** 1625 1626```ts 1627import dataSharePredicates from '@ohos.data.dataSharePredicates'; 1628 1629async function example() { 1630 console.info('onDemo'); 1631 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1632 let fetchOptions: userFileManager.FetchOptions = { 1633 fetchColumns: [], 1634 predicates: predicates 1635 }; 1636 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await mgr.getPhotoAssets(fetchOptions); 1637 let fileAsset: userFileManager.FileAsset = await fetchResult.getFirstObject(); 1638 if (fileAsset != undefined) { 1639 console.info('fileAsset.displayName : ' + fileAsset.displayName); 1640 } 1641 let onCallback1 = (changeData: userFileManager.ChangeData) => { 1642 console.info('onCallback1 success, changData: ' + JSON.stringify(changeData)); 1643 //file had changed, do something 1644 } 1645 let onCallback2 = (changeData: userFileManager.ChangeData) => { 1646 console.info('onCallback2 success, changData: ' + JSON.stringify(changeData)); 1647 // File changed. Do something. 1648 } 1649 // Register onCallback1. 1650 mgr.on(fileAsset.uri, false, onCallback1); 1651 // Register onCallback2. 1652 mgr.on(fileAsset.uri, false, onCallback2); 1653 1654 fileAsset.favorite(true, (err) => { 1655 if (err == undefined) { 1656 console.info('favorite successfully'); 1657 } else { 1658 console.error('favorite failed with error:' + err); 1659 } 1660 }); 1661} 1662``` 1663 1664### off<sup>10+</sup> 1665 1666 off(uri: string, callback?: Callback<ChangeData>): void 1667 1668Unregisters the listener for the specified URI. Multiple callbacks can be registered for a URI for listening. You can use this API to unregister the specified callbacks or all callbacks. 1669 1670**System capability**: SystemCapability.FileManagement.UserFileManager.Core 1671 1672**Parameters** 1673 1674| Name | Type | Mandatory| Description | 1675| -------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | 1676| uri | string | Yes | URI of the file asset or album, or [DefaultChangeUri](#defaultchangeuri10).| 1677| callback | Callback<[ChangeData](#changedata10)> | No | Callback registered by [on<sup>10+</sup>](#on10). If this parameter is not specified, all listener callbacks registered for the URI will be unregistered. <br>**NOTE**: The specified callback will not be invoked.| 1678 1679**Error codes** 1680 1681For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 1682 1683| ID| Error Message| 1684| -------- | ---------------------------------------- | 1685| 13900020 | if parameter is invalid. | 1686 1687**Example** 1688 1689```ts 1690import dataSharePredicates from '@ohos.data.dataSharePredicates'; 1691 1692async function example() { 1693 console.info('offDemo'); 1694 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1695 let fetchOptions: userFileManager.FetchOptions = { 1696 fetchColumns: [], 1697 predicates: predicates 1698 }; 1699 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await mgr.getPhotoAssets(fetchOptions); 1700 let fileAsset: userFileManager.FileAsset = await fetchResult.getFirstObject(); 1701 if (fileAsset != undefined) { 1702 console.info('fileAsset.displayName : ' + fileAsset.displayName); 1703 } 1704 let onCallback1 = (changeData: userFileManager.ChangeData) => { 1705 console.info('onCallback1 on'); 1706 } 1707 let onCallback2 = (changeData: userFileManager.ChangeData) => { 1708 console.info('onCallback2 on'); 1709 } 1710 // Register onCallback1. 1711 mgr.on(fileAsset.uri, false, onCallback1); 1712 // Register onCallback2. 1713 mgr.on(fileAsset.uri, false, onCallback2); 1714 // Disable the listening of onCallback1. 1715 mgr.off(fileAsset.uri, onCallback1); 1716 fileAsset.favorite(true, (err) => { 1717 if (err == undefined) { 1718 console.info('favorite successfully'); 1719 } else { 1720 console.error('favorite failed with error:' + err); 1721 } 1722 }); 1723} 1724``` 1725 1726### on 1727 1728on(type: ChangeEvent, callback: Callback<void>): void 1729 1730Subscribes to changes of the file management library. This API uses a callback to return the result. 1731 1732This API will be deprecated. Use [on<sup>10+</sup>](#on10) instead. 1733 1734**System capability**: SystemCapability.FileManagement.UserFileManager.Core 1735 1736**Parameters** 1737 1738| Name | Type | Mandatory| Description | 1739| -------- | -------------------- | ---- | ------------------------------------------------------------ | 1740| type | [ChangeEvent](#changeevent) | Yes | Type of event to subscribe to.<br>**deviceChange** indicates the device change.<br>**albumChange** indicates the album change.<br>**imageChange** indicates the image change.<br>**audioChange** indicates the audio file change.<br>**videoChange** indicates the video file change.<br>**remoteFileChange** indicates the file change on the registered device.| 1741| callback | Callback<void> | Yes | Callback that returns no value. | 1742 1743**Example** 1744 1745```ts 1746async function example() { 1747 console.info('onDemo'); 1748 let count = 0; 1749 mgr.on('imageChange', () => { 1750 count++; 1751 // Image file changed. Do something. 1752 }); 1753 try { 1754 let testFileName: string = 'testFile' + Date.now() + '.jpg'; 1755 let fileAsset: userFileManager.FileAsset = await mgr.createPhotoAsset(testFileName); 1756 console.info('createPhotoAsset file displayName' + fileAsset.displayName); 1757 console.info('createPhotoAsset successfully'); 1758 } catch (err) { 1759 console.error('createPhotoAsset failed, message = ' + err); 1760 } 1761 // Sleep 1s. 1762 if (count > 0) { 1763 console.info('onDemo success'); 1764 } else { 1765 console.error('onDemo fail'); 1766 } 1767 mgr.off('imageChange', () => { 1768 // Unsubscription succeeds. 1769 }); 1770} 1771``` 1772 1773### off 1774 1775off(type: ChangeEvent, callback?: Callback<void>): void 1776 1777Unsubscribes from changes of the file management library. This API uses a callback to return the result. 1778 1779This API will be deprecated. Use [off<sup>10+</sup>](#off10) instead. 1780 1781**System capability**: SystemCapability.FileManagement.UserFileManager.Core 1782 1783**Parameters** 1784 1785| Name | Type | Mandatory| Description | 1786| -------- | -------------------- | ---- | ------------------------------------------------------------ | 1787| type | [ChangeEvent](#changeevent) | Yes | Type of event to subscribe to.<br>**deviceChange** indicates the device change.<br>**albumChange** indicates the album change.<br>**imageChange** indicates the image change.<br>**audioChange** indicates the audio file change.<br>**videoChange** indicates the video file change.<br>**remoteFileChange** indicates the change of the file on a registered device.| 1788| callback | Callback<void> | No | Callback that returns no value. | 1789 1790**Example** 1791 1792```ts 1793async function example() { 1794 console.info('offDemo'); 1795 let count = 0; 1796 mgr.on('imageChange', () => { 1797 count++; 1798 // Image file changed. Do something. 1799 }); 1800 1801 mgr.off('imageChange', () => { 1802 // Unsubscription succeeds. 1803 }); 1804 1805 try { 1806 let testFileName: string = 'testFile' + Date.now() + '.jpg'; 1807 let fileAsset: userFileManager.FileAsset = await mgr.createPhotoAsset(testFileName); 1808 console.info('createPhotoAsset file displayName' + fileAsset.displayName); 1809 console.info('createPhotoAsset successfully'); 1810 } catch (err) { 1811 console.error('createPhotoAsset failed, message = ' + err); 1812 } 1813 // Sleep 1s. 1814 if (count == 0) { 1815 console.info('offDemo success'); 1816 } else { 1817 console.error('offDemo fail'); 1818 } 1819} 1820``` 1821 1822## FileAsset 1823 1824Provides APIs for encapsulating file asset attributes. 1825 1826### Attributes 1827 1828**System capability**: SystemCapability.FileManagement.UserFileManager.Core 1829 1830| Name | Type | Readable| Writable| Description | 1831| ------------------------- | ------------------------ | ---- | ---- | ------------------------------------------------------ | 1832| uri | string | Yes | No | Media asset URI, for example, **file://media/Photo/1/IMG_datetime_0001/displayName.jpg**. For details, see [Media File URI](../../../application-dev/file-management/user-file-uri-intro.md#media-file-uri). | 1833| fileType | [FileType](#filetype) | Yes | No | Type of the file. | 1834| displayName | string | Yes | Yes | File name, including the file name extension, to display. | 1835 1836### get 1837 1838get(member: string): MemberType; 1839 1840Obtains the value of a **FileAsset** parameter. 1841 1842**System capability**: SystemCapability.FileManagement.UserFileManager.Core 1843 1844**Parameters** 1845 1846| Name | Type | Mandatory | Description | 1847| -------- | ------------------------- | ---- | ----- | 1848| member | string | Yes | Name of the parameter, for example, **ImageVideoKey.URI**.| 1849 1850**Example** 1851 1852```ts 1853import dataSharePredicates from '@ohos.data.dataSharePredicates'; 1854 1855async function example() { 1856 console.info('fileAssetGetDemo'); 1857 try { 1858 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1859 let fetchOption: userFileManager.FetchOptions = { 1860 fetchColumns: ['title'], 1861 predicates: predicates 1862 }; 1863 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await mgr.getPhotoAssets(fetchOption); 1864 let fileAsset: userFileManager.FileAsset = await fetchResult.getFirstObject(); 1865 let title: userFileManager.ImageVideoKey = userFileManager.ImageVideoKey.TITLE; 1866 let fileAssetTitle: userFileManager.MemberType = fileAsset.get(title.toString()); 1867 console.info('fileAsset Get fileAssetTitle = ', fileAssetTitle); 1868 } catch (err) { 1869 console.error('release failed. message = ', err); 1870 } 1871} 1872``` 1873 1874### set 1875 1876set(member: string, value: string): void; 1877 1878Sets a **FileAsset** parameter. 1879 1880**System capability**: SystemCapability.FileManagement.UserFileManager.Core 1881 1882**Parameters** 1883 1884| Name | Type | Mandatory | Description | 1885| -------- | ------------------------- | ---- | ----- | 1886| member | string | Yes | Name of the parameter, for example, **ImageVideoKey.URI**.| 1887| value | string | Yes | Value to set. Only the value of **ImageVideoKey.DISPLAY_NAME** can be changed.| 1888 1889**Example** 1890 1891```ts 1892import dataSharePredicates from '@ohos.data.dataSharePredicates'; 1893 1894async function example() { 1895 console.info('fileAssetSetDemo'); 1896 try { 1897 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1898 let fetchOption: userFileManager.FetchOptions = { 1899 fetchColumns: [], 1900 predicates: predicates 1901 }; 1902 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await mgr.getPhotoAssets(fetchOption); 1903 let fileAsset: userFileManager.FileAsset = await fetchResult.getFirstObject(); 1904 let displayName: string = userFileManager.ImageVideoKey.DISPLAY_NAME.toString(); 1905 fileAsset.set(displayName, 'newDisplayName1'); 1906 } catch (err) { 1907 console.error('release failed. message = ', err); 1908 } 1909} 1910``` 1911 1912### commitModify 1913 1914commitModify(callback: AsyncCallback<void>): void 1915 1916Commits the modification on the file metadata to the database. This API uses an asynchronous callback to return the result. 1917 1918**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.WRITE_AUDIO 1919 1920**System capability**: SystemCapability.FileManagement.UserFileManager.Core 1921 1922**Parameters** 1923 1924| Name | Type | Mandatory | Description | 1925| -------- | ------------------------- | ---- | ----- | 1926| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 1927 1928**Example** 1929 1930```ts 1931import dataSharePredicates from '@ohos.data.dataSharePredicates'; 1932 1933async function example() { 1934 console.info('commitModifyDemo'); 1935 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1936 let fetchOption: userFileManager.FetchOptions = { 1937 fetchColumns: [], 1938 predicates: predicates 1939 }; 1940 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await mgr.getPhotoAssets(fetchOption); 1941 let fileAsset: userFileManager.FileAsset = await fetchResult.getFirstObject(); 1942 let displayName: string = userFileManager.ImageVideoKey.DISPLAY_NAME.toString(); 1943 let fileAssetDisplayName: userFileManager.MemberType = fileAsset.get(displayName); 1944 console.info('fileAsset get fileAssetDisplayName = ', fileAssetDisplayName); 1945 fileAsset.set(displayName, 'newDisplayName2'); 1946 fileAsset.commitModify((err) => { 1947 if (err == undefined) { 1948 let newFileAssetDisplayName: userFileManager.MemberType = fileAsset.get(displayName); 1949 console.info('fileAsset get newFileAssetDisplayName = ', newFileAssetDisplayName); 1950 } else { 1951 console.error('commitModify failed, message =', err); 1952 } 1953 }); 1954} 1955``` 1956 1957### commitModify 1958 1959commitModify(): Promise<void> 1960 1961Commits the modification on the file metadata to the database. This API uses a promise to return the result. 1962 1963**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.WRITE_AUDIO 1964 1965**System capability**: SystemCapability.FileManagement.UserFileManager.Core 1966 1967**Return value** 1968 1969| Type | Description | 1970| ------------------- | ---------- | 1971| Promise<void> | Promise that returns no value.| 1972 1973**Example** 1974 1975```ts 1976import dataSharePredicates from '@ohos.data.dataSharePredicates'; 1977 1978async function example() { 1979 console.info('commitModifyDemo'); 1980 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1981 let fetchOption: userFileManager.FetchOptions = { 1982 fetchColumns: [], 1983 predicates: predicates 1984 }; 1985 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await mgr.getPhotoAssets(fetchOption); 1986 let fileAsset: userFileManager.FileAsset = await fetchResult.getFirstObject(); 1987 let displayName = userFileManager.ImageVideoKey.DISPLAY_NAME.toString(); 1988 let newFileAssetDisplayName: userFileManager.MemberType = fileAsset.get(displayName); 1989 console.info('fileAsset get fileAssetDisplayName = ', fileAssetDisplayName); 1990 fileAsset.set(displayName, 'newDisplayName3'); 1991 try { 1992 await fileAsset.commitModify(); 1993 let newFileAssetDisplayName: userFileManager.MemberType = fileAsset.get(displayName); 1994 console.info('fileAsset get newFileAssetDisplayName = ', newFileAssetDisplayName); 1995 } catch (err) { 1996 console.error('release failed. message = ', err); 1997 } 1998} 1999``` 2000 2001### open 2002 2003open(mode: string, callback: AsyncCallback<number>): void 2004 2005Opens this file asset. This API uses an asynchronous callback to return the result. 2006 2007**NOTE**<br>The write operations are mutually exclusive. After a write operation is complete, you must call **close** to release the resource. 2008 2009**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.READ_AUDIO, ohos.permission.WRITE_IMAGEVIDEO, or ohos.permission.WRITE_AUDIO 2010 2011**System capability**: SystemCapability.FileManagement.UserFileManager.Core 2012 2013**Parameters** 2014 2015| Name | Type | Mandatory | Description | 2016| -------- | --------------------------- | ---- | ----------------------------------- | 2017| mode | string | Yes | File open mode, which can be **r** (read-only), **w** (write-only), or **rw** (read-write).| 2018| callback | AsyncCallback<number> | Yes | Callback invoked to return the file descriptor of the file opened. | 2019 2020**Example** 2021 2022```ts 2023async function example() { 2024 console.info('openDemo'); 2025 let testFileName: string = 'testFile' + Date.now() + '.jpg'; 2026 const fileAsset: userFileManager.FileAsset = await mgr.createPhotoAsset(testFileName); 2027 fileAsset.open('rw', (err, fd) => { 2028 if (fd != undefined) { 2029 console.info('File fd' + fd); 2030 fileAsset.close(fd); 2031 } else { 2032 console.error('File err' + err); 2033 } 2034 }); 2035} 2036``` 2037 2038### open 2039 2040open(mode: string): Promise<number> 2041 2042Opens this file asset. This API uses a promise to return the result. 2043 2044**NOTE**<br>The write operations are mutually exclusive. After a write operation is complete, you must call **close** to release the resource. 2045 2046**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.READ_AUDIO, ohos.permission.WRITE_IMAGEVIDEO, or ohos.permission.WRITE_AUDIO 2047 2048**System capability**: SystemCapability.FileManagement.UserFileManager.Core 2049 2050**Parameters** 2051 2052| Name | Type | Mandatory | Description | 2053| ---- | ------ | ---- | ----------------------------------- | 2054| mode | string | Yes | File open mode, which can be **r** (read-only), **w** (write-only), or **rw** (read-write).| 2055 2056**Return value** 2057 2058| Type | Description | 2059| --------------------- | ------------- | 2060| Promise<number> | Promise used to return the file descriptor of the file opened.| 2061 2062**Example** 2063 2064```ts 2065async function example() { 2066 console.info('openDemo'); 2067 try { 2068 let testFileName: string = 'testFile' + Date.now() + '.jpg'; 2069 const fileAsset: userFileManager.FileAsset = await mgr.createPhotoAsset(testFileName); 2070 let fd: number = await fileAsset.open('rw'); 2071 if (fd != undefined) { 2072 console.info('File fd' + fd); 2073 fileAsset.close(fd); 2074 } else { 2075 console.error(' open File fail'); 2076 } 2077 } catch (err) { 2078 console.error('open Demo err' + err); 2079 } 2080} 2081``` 2082 2083### close 2084 2085close(fd: number, callback: AsyncCallback<void>): void 2086 2087Closes a file asset. This API uses an asynchronous callback to return the result. 2088 2089**System capability**: SystemCapability.FileManagement.UserFileManager.Core 2090 2091**Parameters** 2092 2093| Name | Type | Mandatory | Description | 2094| -------- | ------------------------- | ---- | ----- | 2095| fd | number | Yes | File descriptor of the file to close.| 2096| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 2097 2098**Example** 2099 2100```ts 2101import dataSharePredicates from '@ohos.data.dataSharePredicates'; 2102 2103async function example() { 2104 console.info('closeDemo'); 2105 try { 2106 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2107 let fetchOption: userFileManager.FetchOptions = { 2108 fetchColumns: [], 2109 predicates: predicates 2110 }; 2111 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await mgr.getPhotoAssets(fetchOption); 2112 const fileAsset: userFileManager.FileAsset = await fetchResult.getFirstObject(); 2113 let fd: number = await fileAsset.open('rw'); 2114 console.info('file fd', fd); 2115 fileAsset.close(fd, (err) => { 2116 if (err == undefined) { 2117 console.info('asset close succeed.'); 2118 } else { 2119 console.error('close failed, message = ' + err); 2120 } 2121 }); 2122 } catch (err) { 2123 console.error('close failed, message = ' + err); 2124 } 2125} 2126``` 2127 2128### close 2129 2130close(fd: number): Promise<void> 2131 2132Closes a file asset. This API uses a promise to return the result. 2133 2134**System capability**: SystemCapability.FileManagement.UserFileManager.Core 2135 2136**Parameters** 2137 2138| Name | Type | Mandatory | Description | 2139| ---- | ------ | ---- | ----- | 2140| fd | number | Yes | File descriptor of the file to close.| 2141 2142**Return value** 2143 2144| Type | Description | 2145| ------------------- | ---------- | 2146| Promise<void> | Promise that returns no value.| 2147 2148**Example** 2149 2150```ts 2151import dataSharePredicates from '@ohos.data.dataSharePredicates'; 2152 2153async function example() { 2154 console.info('closeDemo'); 2155 try { 2156 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2157 let fetchOption: userFileManager.FetchOptions = { 2158 fetchColumns: [], 2159 predicates: predicates 2160 }; 2161 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await mgr.getPhotoAssets(fetchOption); 2162 const asset: userFileManager.FileAsset = await fetchResult.getFirstObject(); 2163 let fd: number = await asset.open('rw'); 2164 console.info('file fd', fd); 2165 await asset.close(fd); 2166 console.info('asset close succeed.'); 2167 } catch (err) { 2168 console.error('close failed, message = ' + err); 2169 } 2170} 2171``` 2172 2173### getThumbnail 2174 2175getThumbnail(callback: AsyncCallback<image.PixelMap>): void 2176 2177Obtains the thumbnail of this file asset. This API uses an asynchronous callback to return the result. 2178 2179**Required permissions**: ohos.permission.READ_IMAGEVIDEO or ohos.permission.READ_AUDIO 2180 2181**System capability**: SystemCapability.FileManagement.UserFileManager.Core 2182 2183**Parameters** 2184 2185| Name | Type | Mandatory | Description | 2186| -------- | ----------------------------------- | ---- | ---------------- | 2187| callback | AsyncCallback<[image.PixelMap](js-apis-image.md#pixelmap7)> | Yes | Callback invoked to return the PixelMap of the thumbnail.| 2188 2189**Example** 2190 2191```ts 2192import dataSharePredicates from '@ohos.data.dataSharePredicates'; 2193 2194async function example() { 2195 console.info('getThumbnailDemo'); 2196 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2197 let fetchOption: userFileManager.FetchOptions = { 2198 fetchColumns: [], 2199 predicates: predicates 2200 }; 2201 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await mgr.getPhotoAssets(fetchOption); 2202 let asset: userFileManager.FileAsset = await fetchResult.getFirstObject(); 2203 console.info('asset displayName = ', asset.displayName); 2204 asset.getThumbnail((err, pixelMap) => { 2205 if (err == undefined) { 2206 console.info('getThumbnail successful ' + pixelMap); 2207 } else { 2208 console.error('getThumbnail fail', err); 2209 } 2210 }); 2211} 2212``` 2213 2214### getThumbnail 2215 2216getThumbnail(size: image.Size, callback: AsyncCallback<image.PixelMap>): void 2217 2218Obtains the file thumbnail of the given size. This API uses an asynchronous callback to return the result. 2219 2220**Required permissions**: ohos.permission.READ_IMAGEVIDEO or ohos.permission.READ_AUDIO 2221 2222**System capability**: SystemCapability.FileManagement.UserFileManager.Core 2223 2224**Parameters** 2225 2226| Name | Type | Mandatory | Description | 2227| -------- | ----------------------------------- | ---- | ---------------- | 2228| size | [image.Size](js-apis-image.md#size) | Yes | Size of the thumbnail. | 2229| callback | AsyncCallback<[image.PixelMap](js-apis-image.md#pixelmap7)> | Yes | Callback invoked to return the PixelMap of the thumbnail.| 2230 2231**Example** 2232 2233```ts 2234import dataSharePredicates from '@ohos.data.dataSharePredicates'; 2235import image from '@ohos.multimedia.image'; 2236 2237async function example() { 2238 console.info('getThumbnailDemo'); 2239 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2240 let fetchOption: userFileManager.FetchOptions = { 2241 fetchColumns: [], 2242 predicates: predicates 2243 }; 2244 let size: image.Size = { width: 720, height: 720 }; 2245 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await mgr.getPhotoAssets(fetchOption); 2246 const asset: userFileManager.FileAsset = await fetchResult.getFirstObject(); 2247 console.info('asset displayName = ', asset.displayName); 2248 asset.getThumbnail(size, (err, pixelMap) => { 2249 if (err == undefined) { 2250 console.info('getThumbnail successful ' + pixelMap); 2251 } else { 2252 console.error('getThumbnail fail', err); 2253 } 2254 }); 2255} 2256``` 2257 2258### getThumbnail 2259 2260getThumbnail(size?: image.Size): Promise<image.PixelMap> 2261 2262Obtains the file thumbnail of the given size. This API uses a promise to return the result. 2263 2264**Required permissions**: ohos.permission.READ_IMAGEVIDEO or ohos.permission.READ_AUDIO 2265 2266**System capability**: SystemCapability.FileManagement.UserFileManager.Core 2267 2268**Parameters** 2269 2270| Name | Type | Mandatory | Description | 2271| ---- | -------------- | ---- | ----- | 2272| size | [image.Size](js-apis-image.md#size) | No | Size of the thumbnail.| 2273 2274**Return value** 2275 2276| Type | Description | 2277| ----------------------------- | --------------------- | 2278| Promise<[image.PixelMap](js-apis-image.md#pixelmap7)> | Promise used to return the PixelMap of the thumbnail.| 2279 2280**Example** 2281 2282```ts 2283import dataSharePredicates from '@ohos.data.dataSharePredicates'; 2284import image from '@ohos.multimedia.image'; 2285import { BusinessError } from '@ohos.base'; 2286 2287async function example() { 2288 console.info('getThumbnailDemo'); 2289 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2290 let fetchOption: userFileManager.FetchOptions = { 2291 fetchColumns: [], 2292 predicates: predicates 2293 }; 2294 let size: image.Size = { width: 720, height: 720 }; 2295 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await mgr.getPhotoAssets(fetchOption); 2296 const asset: userFileManager.FileAsset = await fetchResult.getFirstObject(); 2297 console.info('asset displayName = ', asset.displayName); 2298 asset.getThumbnail(size).then((pixelMap) => { 2299 console.info('getThumbnail successful ' + pixelMap); 2300 }).catch((err: BusinessError) => { 2301 console.error('getThumbnail fail' + err); 2302 }); 2303} 2304``` 2305 2306### favorite 2307 2308favorite(isFavorite: boolean, callback: AsyncCallback<void>): void 2309 2310Favorites or unfavorites this file asset. This API uses an asynchronous callback to return the result. 2311 2312**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.WRITE_AUDIO 2313 2314**System capability**: SystemCapability.FileManagement.UserFileManager.Core 2315 2316**Parameters** 2317 2318| Name | Type | Mandatory | Description | 2319| ---------- | ------------------------- | ---- | ---------------------------------- | 2320| isFavorite | boolean | Yes | Operation to perform. The value **true** means to favorite the file asset, and **false** means the opposite.| 2321| callback | AsyncCallback<void> | Yes | Callback that returns no value. | 2322 2323**Example** 2324 2325```ts 2326import dataSharePredicates from '@ohos.data.dataSharePredicates'; 2327 2328async function example() { 2329 console.info('favoriteDemo'); 2330 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2331 let fetchOption: userFileManager.FetchOptions = { 2332 fetchColumns: [], 2333 predicates: predicates 2334 }; 2335 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await mgr.getPhotoAssets(fetchOption); 2336 const asset: userFileManager.FileAsset = await fetchResult.getFirstObject(); 2337 asset.favorite(true, (err) => { 2338 if (err == undefined) { 2339 console.info('favorite successfully'); 2340 } else { 2341 console.error('favorite failed with error:' + err); 2342 } 2343 }); 2344} 2345``` 2346 2347### favorite 2348 2349favorite(isFavorite: boolean): Promise<void> 2350 2351Favorites or unfavorites this file asset. This API uses a promise to return the result. 2352 2353**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.WRITE_AUDIO 2354 2355**System capability**: SystemCapability.FileManagement.UserFileManager.Core 2356 2357**Parameters** 2358 2359| Name | Type | Mandatory | Description | 2360| ---------- | ------- | ---- | ---------------------------------- | 2361| isFavorite | boolean | Yes | Operation to perform. The value **true** means to favorite the file asset, and **false** means the opposite.| 2362 2363**Return value** 2364 2365| Type | Description | 2366| ------------------- | ---------- | 2367| Promise<void> | Promise that returns no value.| 2368 2369**Example** 2370 2371```ts 2372import dataSharePredicates from '@ohos.data.dataSharePredicates'; 2373import { BusinessError } from '@ohos.base'; 2374 2375async function example() { 2376 console.info('favoriteDemo'); 2377 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2378 let fetchOption: userFileManager.FetchOptions = { 2379 fetchColumns: [], 2380 predicates: predicates 2381 }; 2382 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await mgr.getPhotoAssets(fetchOption); 2383 const asset: userFileManager.FileAsset = await fetchResult.getFirstObject(); 2384 asset.favorite(true).then(() => { 2385 console.info('favorite successfully'); 2386 }).catch((err: BusinessError) => { 2387 console.error('favorite failed with error:' + err); 2388 }); 2389} 2390``` 2391 2392### setHidden<sup>10+</sup> 2393 2394setHidden(hiddenState: boolean, callback: AsyncCallback<void>): void 2395 2396Sets this file asset to hidden state. This API uses an asynchronous callback to return the result. 2397 2398The private files set to hidden state are located in the private album (in hidden state) and are not open to third-party applications. After obtaining private files from the private album, users can set **hiddenState** to **false** to remove them from the private album. 2399 2400**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 2401 2402**System capability**: SystemCapability.FileManagement.UserFileManager.Core 2403 2404**Parameters** 2405 2406| Name | Type | Mandatory | Description | 2407| ---------- | ------------------------- | ---- | ---------------------------------- | 2408| hiddenState | boolean | Yes | Whether to set a file to hidden state. The value **true** means to hide the file; the value **false** means the opposite.| 2409| callback | AsyncCallback<void> | Yes | Callback that returns no value. | 2410 2411**Error codes** 2412 2413For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md) and [Universal Error Codes](../errorcodes/errorcode-universal.md). 2414 2415| ID| Error Message| 2416| -------- | ---------------------------------------- | 2417| 202 | Called by non-system application. | 2418| 13900020 | if parameter is invalid. | 2419 2420**Example** 2421 2422```ts 2423import dataSharePredicates from '@ohos.data.dataSharePredicates'; 2424 2425async function example() { 2426 console.info('setHiddenDemo'); 2427 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2428 let fetchOption: userFileManager.FetchOptions = { 2429 fetchColumns: [], 2430 predicates: predicates 2431 }; 2432 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await mgr.getPhotoAssets(fetchOption); 2433 const asset: userFileManager.FileAsset = await fetchResult.getFirstObject(); 2434 asset.setHidden(true, (err) => { 2435 if (err == undefined) { 2436 console.info('setHidden successfully'); 2437 } else { 2438 console.error('setHidden failed with error:' + err); 2439 } 2440 }); 2441} 2442``` 2443 2444### setHidden<sup>10+</sup> 2445 2446setHidden(hiddenState: boolean): Promise<void> 2447 2448Sets this file asset to hidden state. This API uses a promise to return the result. 2449 2450The private files set to hidden state are located in the private album (in hidden state) and are not open to third-party applications. After obtaining private files from the private album, users can set **hiddenState** to **false** to remove them from the private album. 2451 2452**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 2453 2454**System capability**: SystemCapability.FileManagement.UserFileManager.Core 2455 2456**Parameters** 2457 2458| Name | Type | Mandatory | Description | 2459| ---------- | ------- | ---- | ---------------------------------- | 2460| hiddenState | boolean | Yes | Whether to set a file to hidden state. The value **true** means to hide the file; the value **false** means the opposite.| 2461 2462**Return value** 2463 2464| Type | Description | 2465| ------------------- | ---------- | 2466| Promise<void> | Promise that returns no value.| 2467 2468**Error codes** 2469 2470For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md) and [Universal Error Codes](../errorcodes/errorcode-universal.md). 2471 2472| ID| Error Message| 2473| -------- | ---------------------------------------- | 2474| 202 | Called by non-system application. | 2475| 13900020 | if parameter is invalid. | 2476 2477**Example** 2478 2479```ts 2480import dataSharePredicates from '@ohos.data.dataSharePredicates'; 2481import { BusinessError } from '@ohos.base'; 2482 2483async function example() { 2484 // Restore a file from a hidden album. Before the operation, ensure that the file exists in the hidden album. 2485 console.info('setHiddenDemo'); 2486 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2487 let fetchOption: userFileManager.FetchOptions = { 2488 fetchColumns: [], 2489 predicates: predicates 2490 }; 2491 let albumList: userFileManager.FetchResult<userFileManager.Album> = await mgr.getAlbums(userFileManager.AlbumType.SYSTEM, userFileManager.AlbumSubType.HIDDEN); 2492 const album: userFileManager.Album = await albumList.getFirstObject(); 2493 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await album.getPhotoAssets(fetchOption); 2494 const asset: userFileManager.FileAsset = await fetchResult.getFirstObject(); 2495 asset.setHidden(false).then(() => { 2496 console.info('setHidden successfully'); 2497 }).catch((err: BusinessError) => { 2498 console.error('setHidden failed with error:' + err); 2499 }); 2500} 2501``` 2502 2503### getExif<sup>10+</sup> 2504 2505getExif(): Promise<string> 2506 2507Obtains a JSON string consisting of the exchangeable image file format (EXIF) tags of this JPG image. This API uses a promise to return the result. 2508 2509**CAUTION**<br>This API returns a JSON string consisting of EXIF tags. The complete EXIF information consists of **all_exif** and **ImageVideoKey.USER_COMMENT**. These two fields must be passed in via **fetchColumns**. 2510 2511**System API**: This is a system API. 2512 2513**Required permissions**: ohos.permission.READ_IMAGEVIDEO 2514 2515**System capability**: SystemCapability.FileManagement.UserFileManager.Core 2516 2517**Return value** 2518 2519| Type | Description | 2520| --------------------------------------- | ----------------- | 2521| Promise<string> | Promise used to return the JSON string obtained.| 2522 2523**Supported EXIF tags** 2524 2525For details about the EXIF tags, see [image.PropertyKey](js-apis-image.md#propertykey7). 2526 2527| Key Value | Description | 2528| --------------------------------------- | ----------------- | 2529| BitsPerSample | Number of bits per pixel.| 2530| Orientation | Image orientation.| 2531| ImageLength | Image length.| 2532| ImageWidth | Image width.| 2533| GPSLatitude | GPS latitude of the image.| 2534| GPSLongitude | GPS longitude of the image.| 2535| GPSLatitudeRef | Longitude reference, for example, W or E.| 2536| GPSLongitudeRef | Latitude reference, for example, N or S.| 2537| DateTimeOriginal | Shooting time.| 2538| ExposureTime | Exposure time.| 2539| SceneType | Shooting scene type.| 2540| ISOSpeedRatings | ISO sensitivity or speed.| 2541| FNumber | f-number.| 2542| DateTime | Date and time when the image was last modified.| 2543| GPSTimeStamp | GPS timestamp.| 2544| GPSDateStamp | GPS date stamp.| 2545| ImageDescription | Image description.| 2546| Make | Camera vendor.| 2547| Model | Model.| 2548| PhotoMode | Photo mode.| 2549| SensitivityType | Sensitivity type.| 2550| StandardOutputSensitivity | Standard output sensitivity.| 2551| RecommendedExposureIndex | Recommended exposure index.| 2552| ApertureValue | Aperture value.| 2553| MeteringMode | Metering mode.| 2554| LightSource | Light source.| 2555| Flash | Flash status.| 2556| FocalLength | Focal length.| 2557| UserComment | User comment.| 2558| PixelXDimension | Pixel X dimension.| 2559| PixelYDimension | Pixel Y dimension.| 2560| WhiteBalance | White balance.| 2561| FocalLengthIn35mmFilm | Focal length in 35 mm film.| 2562| ExposureBiasValue | Exposure compensation.| 2563 2564**Example** 2565 2566```ts 2567import dataSharePredicates from '@ohos.data.dataSharePredicates'; 2568 2569async function example() { 2570 try { 2571 console.info('getExifDemo'); 2572 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2573 predicates.isNotNull('all_exif') 2574 let fetchOptions: userFileManager.FetchOptions = { 2575 fetchColumns: ['all_exif', userFileManager.ImageVideoKey.USER_COMMENT.toString()], 2576 predicates: predicates 2577 }; 2578 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await mgr.getPhotoAssets(fetchOptions); 2579 let fileAsset: userFileManager.FileAsset = await fetchResult.getFirstObject(); 2580 console.info('getExifDemo fileAsset displayName: ' + JSON.stringify(fileAsset.displayName)); 2581 let exifMessage: string = await fileAsset.getExif(); 2582 let userCommentKey: string = 'UserComment'; 2583 let userComment: string = JSON.stringify(JSON.parse(exifMessage), [userCommentKey]); 2584 console.info('getExifDemo userComment: ' + JSON.stringify(userComment)); 2585 fetchResult.close(); 2586 } catch (err) { 2587 console.error('getExifDemoCallback failed with error: ' + err); 2588 } 2589} 2590``` 2591 2592### getExif<sup>10+</sup> 2593 2594getExif(callback: AsyncCallback<string>): void 2595 2596Obtains a JSON string consisting of the EXIF tags of this JPG image. This API uses an asynchronous callback to return the result. 2597 2598**CAUTION**<br>This API returns a JSON string consisting of EXIF tags. The complete EXIF information consists of **all_exif** and **ImageVideoKey.USER_COMMENT**. These two fields must be passed in via **fetchColumns**. 2599 2600**System API**: This is a system API. 2601 2602**Required permissions**: ohos.permission.READ_IMAGEVIDEO 2603 2604**System capability**: SystemCapability.FileManagement.UserFileManager.Core 2605 2606**Parameters** 2607 2608| Name | Type | Mandatory| Description | 2609| -------- | ------------------------- | ---- | ---------- | 2610| callback | AsyncCallback<string> | Yes | Callback invoked to return the JSON string obtained.| 2611 2612**Supported EXIF tags** 2613 2614For details about the EXIF tags, see [image.PropertyKey](js-apis-image.md#propertykey7). 2615 2616| Key Value | Description | 2617| --------------------------------------- | ----------------- | 2618| BitsPerSample | Number of bits per pixel.| 2619| Orientation | Image orientation.| 2620| ImageLength | Image length.| 2621| ImageWidth | Image width.| 2622| GPSLatitude | GPS latitude of the image.| 2623| GPSLongitude | GPS longitude of the image.| 2624| GPSLatitudeRef | Longitude reference, for example, W or E.| 2625| GPSLongitudeRef | Latitude reference, for example, N or S.| 2626| DateTimeOriginal | Shooting time.| 2627| ExposureTime | Exposure time.| 2628| SceneType | Shooting scene type.| 2629| ISOSpeedRatings | ISO sensitivity or speed.| 2630| FNumber | f-number.| 2631| DateTime | Date and time when the image was last modified.| 2632| GPSTimeStamp | GPS timestamp.| 2633| GPSDateStamp | GPS date stamp.| 2634| ImageDescription | Image description.| 2635| Make | Camera vendor.| 2636| Model | Model.| 2637| PhotoMode | Photo mode.| 2638| SensitivityType | Sensitivity type.| 2639| StandardOutputSensitivity | Standard output sensitivity.| 2640| RecommendedExposureIndex | Recommended exposure index.| 2641| ApertureValue | Aperture value.| 2642| MeteringMode | Metering mode.| 2643| LightSource | Light source.| 2644| Flash | Flash status.| 2645| FocalLength | Focal length.| 2646| UserComment | User comment.| 2647| PixelXDimension | Pixel X dimension.| 2648| PixelYDimension | Pixel Y dimension.| 2649| WhiteBalance | White balance.| 2650| FocalLengthIn35mmFilm | Focal length in 35 mm film.| 2651| ExposureBiasValue | Exposure compensation.| 2652 2653**Example** 2654 2655```ts 2656import dataSharePredicates from '@ohos.data.dataSharePredicates'; 2657 2658async function example() { 2659 try { 2660 console.info('getExifDemo'); 2661 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2662 predicates.isNotNull('all_exif') 2663 let fetchOptions: userFileManager.FetchOptions = { 2664 fetchColumns: ['all_exif', userFileManager.ImageVideoKey.USER_COMMENT.toString()], 2665 predicates: predicates 2666 }; 2667 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await mgr.getPhotoAssets(fetchOptions); 2668 let fileAsset: userFileManager.FileAsset = await fetchResult.getFirstObject(); 2669 console.info('getExifDemo fileAsset displayName: ' + JSON.stringify(fileAsset.displayName)); 2670 let userCommentKey: string = 'UserComment'; 2671 fileAsset.getExif((err, exifMessage) => { 2672 if (exifMessage != undefined) { 2673 let userComment: string = JSON.stringify(JSON.parse(exifMessage), [userCommentKey]); 2674 console.info('getExifDemo userComment: ' + JSON.stringify(userComment)); 2675 } else { 2676 console.error('getExif failed, message = ', err); 2677 } 2678 }); 2679 fetchResult.close(); 2680 } catch (err) { 2681 console.error('getExifDemoCallback failed with error: ' + err); 2682 } 2683} 2684``` 2685 2686### setUserComment<sup>10+</sup> 2687 2688setUserComment(userComment: string): Promise<void> 2689 2690Sets user comment information of an image or video. This API uses a promise to return the result. 2691 2692**NOTE**<br>This API can be used to modify the comment information of only images or videos. 2693 2694**System API**: This is a system API. 2695 2696**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 2697 2698**System capability**: SystemCapability.FileManagement.UserFileManager.Core 2699 2700**Parameters** 2701 2702| Name | Type | Mandatory| Description | 2703| -------- | ------------------------- | ---- | ---------- | 2704| userComment | string | Yes | User comment information to set, which cannot exceed 140 characters.| 2705 2706**Return value** 2707 2708| Type | Description | 2709| --------------------------------------- | ----------------- | 2710|Promise<void> | Promise that returns no value.| 2711 2712**Example** 2713 2714```ts 2715import dataSharePredicates from '@ohos.data.dataSharePredicates'; 2716 2717async function example() { 2718 try { 2719 console.info('setUserCommentDemo') 2720 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2721 let fetchOptions: userFileManager.FetchOptions = { 2722 fetchColumns: [], 2723 predicates: predicates 2724 }; 2725 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await mgr.getPhotoAssets(fetchOptions); 2726 let fileAsset: userFileManager.FileAsset = await fetchResult.getFirstObject(); 2727 let userComment: string = 'test_set_user_comment'; 2728 await fileAsset.setUserComment(userComment); 2729 } catch (err) { 2730 console.error('setUserCommentDemoCallback failed with error: ' + err); 2731 } 2732} 2733``` 2734 2735### setUserComment<sup>10+</sup> 2736 2737setUserComment(userComment: string, callback: AsyncCallback<void>): void 2738 2739Sets user comment information of an image or video. This API uses an asynchronous callback to return the result. 2740 2741**NOTE**<br>This API can be used to modify the comment information of only images or videos. 2742 2743**System API**: This is a system API. 2744 2745**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 2746 2747**System capability**: SystemCapability.FileManagement.UserFileManager.Core 2748 2749**Parameters** 2750 2751| Name | Type | Mandatory| Description | 2752| -------- | ------------------------- | ---- | ---------- | 2753| userComment | string | Yes | User comment information to set, which cannot exceed 140 characters.| 2754| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 2755 2756**Example** 2757 2758```ts 2759import dataSharePredicates from '@ohos.data.dataSharePredicates'; 2760 2761async function example() { 2762 try { 2763 console.info('setUserCommentDemo') 2764 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2765 let fetchOptions: userFileManager.FetchOptions = { 2766 fetchColumns: [], 2767 predicates: predicates 2768 }; 2769 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await mgr.getPhotoAssets(fetchOptions); 2770 let fileAsset: userFileManager.FileAsset = await fetchResult.getFirstObject(); 2771 let userComment: string = 'test_set_user_comment'; 2772 fileAsset.setUserComment(userComment, (err) => { 2773 if (err === undefined) { 2774 console.info('setUserComment successfully'); 2775 } else { 2776 console.error('setUserComment failed with error: ' + err); 2777 } 2778 }); 2779 } catch (err) { 2780 console.error('setUserCommentDemoCallback failed with error: ' + err); 2781 } 2782} 2783``` 2784 2785## FetchResult 2786 2787Provides APIs to manage the file retrieval result. 2788 2789### getCount 2790 2791getCount(): number 2792 2793Obtains the total number of files in the result set. 2794 2795**System capability**: SystemCapability.FileManagement.UserFileManager.Core 2796 2797**Return value** 2798 2799| Type | Description | 2800| ------ | -------- | 2801| number | Returns the total number of files obtained.| 2802 2803**Example** 2804 2805```ts 2806import dataSharePredicates from '@ohos.data.dataSharePredicates'; 2807 2808async function example() { 2809 console.info('getCountDemo'); 2810 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2811 let fetchOption: userFileManager.FetchOptions = { 2812 fetchColumns: [], 2813 predicates: predicates 2814 }; 2815 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await mgr.getPhotoAssets(fetchOption); 2816 const fetchCount: number = fetchResult.getCount(); 2817 console.info('fetchCount = ', fetchCount); 2818} 2819``` 2820 2821### isAfterLast 2822 2823isAfterLast(): boolean 2824 2825Checks whether the cursor is in the last row of the result set. 2826 2827**System capability**: SystemCapability.FileManagement.UserFileManager.Core 2828 2829**Return value** 2830 2831| Type | Description | 2832| ------- | ---------------------------------- | 2833| boolean | Returns **true** if the cursor is in the last row of the result set; returns **false** otherwise.| 2834 2835**Example** 2836 2837```ts 2838import dataSharePredicates from '@ohos.data.dataSharePredicates'; 2839 2840async function example() { 2841 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2842 let fetchOption: userFileManager.FetchOptions = { 2843 fetchColumns: [], 2844 predicates: predicates 2845 }; 2846 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await mgr.getPhotoAssets(fetchOption); 2847 const fetchCount: number = fetchResult.getCount(); 2848 console.info('count:' + fetchCount); 2849 let fileAsset: userFileManager.FileAsset = await fetchResult.getLastObject(); 2850 if (fetchResult.isAfterLast()) { 2851 console.info('fileAsset isAfterLast displayName = ', fileAsset.displayName); 2852 } else { 2853 console.info('fileAsset not isAfterLast '); 2854 } 2855} 2856``` 2857 2858### close 2859 2860close(): void 2861 2862Releases and invalidates this **FetchFileResult** instance. After this instance is released, the APIs in this instance cannot be invoked. 2863 2864**System capability**: SystemCapability.FileManagement.UserFileManager.Core 2865 2866**Example** 2867 2868```ts 2869import dataSharePredicates from '@ohos.data.dataSharePredicates'; 2870 2871async function example() { 2872 console.info('fetchResultCloseDemo'); 2873 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2874 let fetchOption: userFileManager.FetchOptions = { 2875 fetchColumns: [], 2876 predicates: predicates 2877 }; 2878 try { 2879 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await mgr.getPhotoAssets(fetchOption); 2880 await fetchResult.close(); 2881 console.info('close succeed.'); 2882 } catch (err) { 2883 console.error('close fail. message = ' + err); 2884 } 2885} 2886``` 2887 2888### getFirstObject 2889 2890getFirstObject(callback: AsyncCallback<T>): void 2891 2892Obtains the first file asset in the result set. This API uses an asynchronous callback to return the result. 2893 2894**System capability**: SystemCapability.FileManagement.UserFileManager.Core 2895 2896**Parameters** 2897 2898| Name | Type | Mandatory| Description | 2899| -------- | --------------------------------------------- | ---- | ------------------------------------------- | 2900| callback | AsyncCallback<T> | Yes | Callback invoked to return the first file asset.| 2901 2902**Example** 2903 2904```ts 2905import dataSharePredicates from '@ohos.data.dataSharePredicates'; 2906 2907async function example() { 2908 console.info('getFirstObjectDemo'); 2909 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2910 let fetchOption: userFileManager.FetchOptions = { 2911 fetchColumns: [], 2912 predicates: predicates 2913 }; 2914 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await mgr.getPhotoAssets(fetchOption); 2915 fetchResult.getFirstObject((err, fileAsset) => { 2916 if (fileAsset != undefined) { 2917 console.info('fileAsset displayName: ', fileAsset.displayName); 2918 } else { 2919 console.error('fileAsset failed with err:' + err); 2920 } 2921 }); 2922} 2923``` 2924 2925### getFirstObject 2926 2927getFirstObject(): Promise<T> 2928 2929Obtains the first file asset in the result set. This API uses a promise to return the result. 2930 2931**System capability**: SystemCapability.FileManagement.UserFileManager.Core 2932 2933**Return value** 2934 2935| Type | Description | 2936| --------------------------------------- | -------------------------- | 2937| Promise<T> | Promise used to return the first object in the result set.| 2938 2939**Example** 2940 2941```ts 2942import dataSharePredicates from '@ohos.data.dataSharePredicates'; 2943 2944async function example() { 2945 console.info('getFirstObjectDemo'); 2946 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2947 let fetchOption: userFileManager.FetchOptions = { 2948 fetchColumns: [], 2949 predicates: predicates 2950 }; 2951 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await mgr.getPhotoAssets(fetchOption); 2952 let fileAsset: userFileManager.FileAsset = await fetchResult.getFirstObject(); 2953 console.info('fileAsset displayName: ', fileAsset.displayName); 2954} 2955``` 2956 2957### getNextObject 2958 2959 getNextObject(callback: AsyncCallback<T>): void 2960 2961Obtains the next file asset in the result set. This API uses an asynchronous callback to return the result. 2962 2963**System capability**: SystemCapability.FileManagement.UserFileManager.Core 2964 2965**Parameters** 2966 2967| Name | Type | Mandatory| Description | 2968| --------- | --------------------------------------------- | ---- | ----------------------------------------- | 2969| callbacke | AsyncCallback<T> | Yes | Callback invoked to return the next file asset.| 2970 2971**Example** 2972 2973```ts 2974import dataSharePredicates from '@ohos.data.dataSharePredicates'; 2975 2976async function example() { 2977 console.info('getNextObjectDemo'); 2978 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2979 let fetchOption: userFileManager.FetchOptions = { 2980 fetchColumns: [], 2981 predicates: predicates 2982 }; 2983 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await mgr.getPhotoAssets(fetchOption); 2984 await fetchResult.getFirstObject(); 2985 if (fetchResult.isAfterLast()) { 2986 fetchResult.getNextObject((err, fileAsset) => { 2987 if (fileAsset != undefined) { 2988 console.info('fileAsset displayName: ', fileAsset.displayName); 2989 } else { 2990 console.error('fileAsset failed with err: ' + err); 2991 } 2992 }); 2993 } 2994} 2995``` 2996 2997### getNextObject 2998 2999 getNextObject(): Promise<T> 3000 3001Obtains the next file asset in the result set. This API uses a promise to return the result. 3002 3003**System capability**: SystemCapability.FileManagement.UserFileManager.Core 3004 3005**Return value** 3006 3007| Type | Description | 3008| --------------------------------------- | ----------------- | 3009| Promise<T> | Promise used to return the next object in the result set.| 3010 3011**Example** 3012 3013```ts 3014import dataSharePredicates from '@ohos.data.dataSharePredicates'; 3015 3016async function example() { 3017 console.info('getNextObjectDemo'); 3018 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3019 let fetchOption: userFileManager.FetchOptions = { 3020 fetchColumns: [], 3021 predicates: predicates 3022 }; 3023 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await mgr.getPhotoAssets(fetchOption); 3024 await fetchResult.getFirstObject(); 3025 if (fetchResult.isAfterLast()) { 3026 let fileAsset: userFileManager.FileAsset = await fetchResult.getNextObject(); 3027 console.info('fileAsset displayName: ', fileAsset.displayName); 3028 } 3029} 3030``` 3031 3032### getLastObject 3033 3034getLastObject(callback: AsyncCallback<T>): void 3035 3036Obtains the last file asset in the result set. This API uses an asynchronous callback to return the result. 3037 3038**System capability**: SystemCapability.FileManagement.UserFileManager.Core 3039 3040**Parameters** 3041 3042| Name | Type | Mandatory| Description | 3043| -------- | --------------------------------------------- | ---- | --------------------------- | 3044| callback | AsyncCallback<T> | Yes | Callback invoked to return the last file asset obtained.| 3045 3046**Example** 3047 3048```ts 3049import dataSharePredicates from '@ohos.data.dataSharePredicates'; 3050 3051async function example() { 3052 console.info('getLastObjectDemo'); 3053 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3054 let fetchOption: userFileManager.FetchOptions = { 3055 fetchColumns: [], 3056 predicates: predicates 3057 }; 3058 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await mgr.getPhotoAssets(fetchOption); 3059 fetchResult.getLastObject((err, fileAsset) => { 3060 if (fileAsset != undefined) { 3061 console.info('fileAsset displayName: ', fileAsset.displayName); 3062 } else { 3063 console.error('fileAsset failed with err: ' + err); 3064 } 3065 }); 3066} 3067``` 3068 3069### getLastObject 3070 3071getLastObject(): Promise<T> 3072 3073Obtains the last file asset in the result set. This API uses a promise to return the result. 3074 3075**System capability**: SystemCapability.FileManagement.UserFileManager.Core 3076 3077**Return value** 3078 3079| Type | Description | 3080| --------------------------------------- | ----------------- | 3081| Promise<T> | Promise used to return the last object in the result set.| 3082 3083**Example** 3084 3085```ts 3086import dataSharePredicates from '@ohos.data.dataSharePredicates'; 3087 3088async function example() { 3089 console.info('getLastObjectDemo'); 3090 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3091 let fetchOption: userFileManager.FetchOptions = { 3092 fetchColumns: [], 3093 predicates: predicates 3094 }; 3095 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await mgr.getPhotoAssets(fetchOption); 3096 let fileAsset: userFileManager.FileAsset = await fetchResult.getLastObject(); 3097 console.info('fileAsset displayName: ', fileAsset.displayName); 3098} 3099``` 3100 3101### getPositionObject 3102 3103getPositionObject(index: number, callback: AsyncCallback<T>): void 3104 3105Obtains a file asset with the specified index in the result set. This API uses an asynchronous callback to return the result. 3106 3107**System capability**: SystemCapability.FileManagement.UserFileManager.Core 3108 3109**Parameters** 3110 3111| Name | Type | Mandatory | Description | 3112| -------- | ---------------------------------------- | ---- | ------------------ | 3113| index | number | Yes | Index of the file asset to obtain. The value starts from **0**. | 3114| callback | AsyncCallback<T> | Yes | Callback invoked to return the file asset obtained.| 3115 3116**Error codes** 3117 3118For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 3119 3120| ID| Error Message| 3121| -------- | ---------------------------------------- | 3122| 13900020 | if type index is not number. | 3123 3124**Example** 3125 3126```ts 3127import dataSharePredicates from '@ohos.data.dataSharePredicates'; 3128 3129async function example() { 3130 console.info('getPositionObjectDemo'); 3131 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3132 let fetchOption: userFileManager.FetchOptions = { 3133 fetchColumns: [], 3134 predicates: predicates 3135 }; 3136 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await mgr.getPhotoAssets(fetchOption); 3137 fetchResult.getPositionObject(0, (err, fileAsset) => { 3138 if (fileAsset != undefined) { 3139 console.info('fileAsset displayName: ', fileAsset.displayName); 3140 } else { 3141 console.error('fileAsset failed with err: ' + err); 3142 } 3143 }); 3144} 3145``` 3146 3147### getPositionObject 3148 3149getPositionObject(index: number): Promise<T> 3150 3151Obtains a file asset with the specified index in the result set. This API uses a promise to return the result. 3152 3153**System capability**: SystemCapability.FileManagement.UserFileManager.Core 3154 3155**Parameters** 3156 3157| Name | Type | Mandatory | Description | 3158| ----- | ------ | ---- | -------------- | 3159| index | number | Yes | Index of the file asset to obtain. The value starts from **0**.| 3160 3161**Return value** 3162 3163| Type | Description | 3164| --------------------------------------- | ----------------- | 3165| Promise<T> | Promise used to return the file asset obtained.| 3166 3167**Error codes** 3168 3169For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 3170 3171| ID| Error Message| 3172| -------- | ---------------------------------------- | 3173| 13900020 | if type index is not number. | 3174 3175**Example** 3176 3177```ts 3178import dataSharePredicates from '@ohos.data.dataSharePredicates'; 3179 3180async function example() { 3181 console.info('getPositionObjectDemo'); 3182 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3183 let fetchOption: userFileManager.FetchOptions = { 3184 fetchColumns: [], 3185 predicates: predicates 3186 }; 3187 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await mgr.getPhotoAssets(fetchOption); 3188 let fileAsset: userFileManager.FileAsset = await fetchResult.getPositionObject(0); 3189 console.info('fileAsset displayName: ', fileAsset.displayName); 3190} 3191``` 3192 3193### getAllObject<sup>10+</sup> 3194 3195getAllObject(callback: AsyncCallback<Array<T>>): void 3196 3197Obtains all the file assets in the result set. This API uses an asynchronous callback to return the result. 3198 3199**System capability**: SystemCapability.FileManagement.UserFileManager.Core 3200 3201**Parameters** 3202 3203| Name | Type | Mandatory| Description | 3204| -------- | --------------------------------------------- | ---- | ------------------------------------------- | 3205| callback | AsyncCallback<Array<T>> | Yes | Callback invoked to return an array of all file assets in the result set.| 3206 3207**Example** 3208 3209```ts 3210import dataSharePredicates from '@ohos.data.dataSharePredicates'; 3211 3212async function example() { 3213 console.info('getAllObjectDemo'); 3214 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3215 let fetchOption: userFileManager.FetchOptions = { 3216 fetchColumns: [], 3217 predicates: predicates 3218 }; 3219 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await mgr.getPhotoAssets(fetchOption); 3220 fetchResult.getAllObject((err, fileAssetList) => { 3221 if (fileAssetList != undefined) { 3222 console.info('fileAssetList length: ', fileAssetList.length); 3223 } else { 3224 console.error('fileAssetList failed with err:' + err); 3225 } 3226 }); 3227} 3228``` 3229 3230### getAllObject<sup>10+</sup> 3231 3232getAllObject(): Promise<Array<T>> 3233 3234Obtains all the file assets in the result set. This API uses a promise to return the result. 3235 3236**System capability**: SystemCapability.FileManagement.UserFileManager.Core 3237 3238**Return value** 3239 3240| Type | Description | 3241| --------------------------------------- | -------------------------- | 3242| Promise<Array<T>> | Promise used to return an array of all file assets in the result set.| 3243 3244**Example** 3245 3246```ts 3247import dataSharePredicates from '@ohos.data.dataSharePredicates'; 3248 3249async function example() { 3250 console.info('getAllObjectDemo'); 3251 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3252 let fetchOption: userFileManager.FetchOptions = { 3253 fetchColumns: [], 3254 predicates: predicates 3255 }; 3256 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await mgr.getPhotoAssets(fetchOption); 3257 let fileAssetList: Array<userFileManager.FileAsset> = await fetchResult.getAllObject(); 3258 console.info('fileAssetList length: ', fileAssetList.length); 3259} 3260``` 3261 3262## Album 3263 3264Provides APIs to manage albums. 3265 3266### Attributes 3267 3268**System capability**: SystemCapability.FileManagement.UserFileManager.Core 3269 3270| Name | Type | Readable | Writable | Description | 3271| ------------ | ------ | ---- | ---- | ------- | 3272| albumType<sup>10+</sup> | [AlbumType]( #albumtype10) | Yes | No | Type of the album. | 3273| albumSubType<sup>10+</sup> | [AlbumSubType]( #albumsubtype10) | Yes | No | Subtype of the album. | 3274| albumName | string | Yes | Yes for a user album; no for a system album. | Name of the album. | 3275| albumUri | string | Yes | No | URI of the album. | 3276| count | number | Yes | No | Number of files in the album.| 3277| coverUri | string | Yes | Yes for a user album; no for a system album. | URI of the cover file of the album.| 3278 3279### getPhotoAssets 3280 3281getPhotoAssets(options: FetchOptions, callback: AsyncCallback<FetchResult<FileAsset>>): void; 3282 3283Obtains image and video assets. This API uses an asynchronous callback to return the result. 3284 3285**Required permissions**: ohos.permission.READ_IMAGEVIDEO 3286 3287**System capability**: SystemCapability.FileManagement.UserFileManager.Core 3288 3289**Parameters** 3290 3291| Name | Type | Mandatory| Description | 3292| -------- | ------------------------- | ---- | ---------- | 3293| options | [FetchOptions](#fetchoptions) | Yes | Options for fetching the image and video assets.| 3294| callback | AsyncCallback<[FetchResult](#fetchresult)<[FileAsset](#fileasset)>> | Yes | Callback invoked to return the image and video assets obtained.| 3295 3296**Error codes** 3297 3298For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 3299 3300| ID| Error Message| 3301| -------- | ---------------------------------------- | 3302| 13900020 | if type options is not FetchOptions. | 3303 3304**Example** 3305 3306```ts 3307import dataSharePredicates from '@ohos.data.dataSharePredicates'; 3308 3309async function example() { 3310 console.info('albumGetFileAssetsDemoCallback'); 3311 3312 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3313 let albumFetchOptions: userFileManager.AlbumFetchOptions = { 3314 predicates: predicates 3315 }; 3316 let fetchOption: userFileManager.FetchOptions = { 3317 fetchColumns: [], 3318 predicates: predicates 3319 }; 3320 let albumList: userFileManager.FetchResult<userFileManager.Album> = await mgr.getPhotoAlbums(albumFetchOptions); 3321 let album: userFileManager.Album = await albumList.getFirstObject(); 3322 album.getPhotoAssets(fetchOption, (err, albumFetchResult) => { 3323 if (albumFetchResult != undefined) { 3324 console.info('album getPhotoAssets successfully, getCount: ' + albumFetchResult.getCount()); 3325 } else { 3326 console.error('album getPhotoAssets failed with error: ' + err); 3327 } 3328 }); 3329} 3330``` 3331 3332### getPhotoAssets 3333 3334getPhotoAssets(options: FetchOptions): Promise<FetchResult<FileAsset>>; 3335 3336Obtains image and video assets. This API uses a promise to return the result. 3337 3338**Required permissions**: ohos.permission.READ_IMAGEVIDEO 3339 3340**System capability**: SystemCapability.FileManagement.UserFileManager.Core 3341 3342**Parameters** 3343 3344| Name | Type | Mandatory| Description | 3345| -------- | ------------------------- | ---- | ---------- | 3346| options | [FetchOptions](#fetchoptions) | Yes | Options for fetching the image and video assets.| 3347 3348**Return value** 3349 3350| Type | Description | 3351| --------------------------------------- | ----------------- | 3352| Promise<[FetchResult](#fetchresult)<[FileAsset](#fileasset)>> | Promise used to return the image and video assets obtained.| 3353 3354**Error codes** 3355 3356For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 3357 3358| ID| Error Message| 3359| -------- | ---------------------------------------- | 3360| 13900020 | if type options is not FetchOptions. | 3361 3362**Example** 3363 3364```ts 3365import dataSharePredicates from '@ohos.data.dataSharePredicates'; 3366import { BusinessError } from '@ohos.base'; 3367 3368async function example() { 3369 console.info('albumGetFileAssetsDemoPromise'); 3370 3371 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3372 let albumFetchOptions: userFileManager.AlbumFetchOptions = { 3373 predicates: predicates 3374 }; 3375 let fetchOption: userFileManager.FetchOptions = { 3376 fetchColumns: [], 3377 predicates: predicates 3378 }; 3379 const albumList: userFileManager.FetchResult<userFileManager.Album> = await mgr.getPhotoAlbums(albumFetchOptions); 3380 const album: userFileManager.Album = await albumList.getFirstObject(); 3381 album.getPhotoAssets(fetchOption).then((albumFetchResult) => { 3382 console.info('album getFileAssets successfully, getCount: ' + albumFetchResult.getCount()); 3383 }).catch((err: BusinessError) => { 3384 console.error('album getFileAssets failed with error: ' + err); 3385 }); 3386} 3387``` 3388 3389### commitModify 3390 3391commitModify(callback: AsyncCallback<void>): void; 3392 3393Commits the modification on the album attributes to the database. This API uses an asynchronous callback to return the result. 3394 3395**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 3396 3397**System capability**: SystemCapability.FileManagement.UserFileManager.Core 3398 3399**Parameters** 3400 3401| Name | Type | Mandatory| Description | 3402| -------- | ------------------------- | ---- | ---------- | 3403| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 3404 3405**Example** 3406 3407```ts 3408import dataSharePredicates from '@ohos.data.dataSharePredicates'; 3409 3410async function example() { 3411 console.info('albumCommitModifyDemo'); 3412 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3413 let albumFetchOptions: userFileManager.AlbumFetchOptions = { 3414 predicates: predicates 3415 }; 3416 const albumList: userFileManager.FetchResult<userFileManager.Album> = await mgr.getPhotoAlbums(albumFetchOptions); 3417 const album: userFileManager.Album = await albumList.getFirstObject(); 3418 album.albumName = 'hello'; 3419 album.commitModify((err) => { 3420 if (err != undefined) { 3421 console.error('commitModify failed with error: ' + err); 3422 } else { 3423 console.info('commitModify successfully'); 3424 } 3425 }); 3426} 3427``` 3428 3429### commitModify 3430 3431commitModify(): Promise<void>; 3432 3433Commits the modification on the album attributes to the database. This API uses a promise to return the result. 3434 3435**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 3436 3437**System capability**: SystemCapability.FileManagement.UserFileManager.Core 3438 3439**Return value** 3440 3441| Type | Description | 3442| ------------------- | ------------ | 3443| Promise<void> | Promise that returns no value.| 3444 3445**Example** 3446 3447```ts 3448import dataSharePredicates from '@ohos.data.dataSharePredicates'; 3449import { BusinessError } from '@ohos.base'; 3450 3451async function example() { 3452 console.info('albumCommitModifyDemo'); 3453 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3454 let albumFetchOptions: userFileManager.AlbumFetchOptions = { 3455 predicates: predicates 3456 }; 3457 try { 3458 let albumList: userFileManager.FetchResult<userFileManager.Album> = await mgr.getPhotoAlbums(albumFetchOptions); 3459 let album: userFileManager.Album = await albumList.getFirstObject(); 3460 album.albumName = 'hello'; 3461 album.commitModify().then(() => { 3462 console.info('commitModify successfully'); 3463 }).catch((err: BusinessError) => { 3464 console.error('commitModify failed with error: ' + err); 3465 }); 3466 } catch (err) { 3467 console.error('getPhotoAlbums failed. message = ', err); 3468 } 3469} 3470``` 3471 3472### addPhotoAssets<sup>10+</sup> 3473 3474addPhotoAssets(assets: Array<FileAsset>, callback: AsyncCallback<void>): void; 3475 3476Adds 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. 3477 3478**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 3479 3480**System capability**: SystemCapability.FileManagement.UserFileManager.Core 3481 3482**Parameters** 3483 3484| Name | Type | Mandatory| Description | 3485| -------- | ------------------------- | ---- | ---------- | 3486| assets | Array<[FileAsset](#fileasset)> | Yes | Array of the image and video assets to add.| 3487| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 3488 3489**Error codes** 3490 3491For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 3492 3493| ID| Error Message| 3494| -------- | ---------------------------------------- | 3495| 13900020 | if PhotoAssets is invalid. | 3496 3497**Example** 3498 3499```ts 3500import dataSharePredicates from '@ohos.data.dataSharePredicates'; 3501 3502async function example() { 3503 try { 3504 console.info('addPhotoAssetsDemoCallback'); 3505 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3506 let fetchOption: userFileManager.FetchOptions = { 3507 fetchColumns: [], 3508 predicates: predicates 3509 }; 3510 let albumFetchResult: userFileManager.FetchResult<userFileManager.Album> = await mgr.getAlbums(userFileManager.AlbumType.USER, userFileManager.AlbumSubType.USER_GENERIC); 3511 let album: userFileManager.Album = await albumFetchResult.getFirstObject(); 3512 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await mgr.getPhotoAssets(fetchOption); 3513 let asset: userFileManager.FileAsset = await fetchResult.getFirstObject(); 3514 album.addPhotoAssets([asset], (err) => { 3515 if (err === undefined) { 3516 console.info('album addPhotoAssets successfully'); 3517 } else { 3518 console.error('album addPhotoAssets failed with error: ' + err); 3519 } 3520 }); 3521 } catch (err) { 3522 console.error('addPhotoAssetsDemoCallback failed with error: ' + err); 3523 } 3524} 3525``` 3526 3527### addPhotoAssets<sup>10+</sup> 3528 3529addPhotoAssets(assets: Array<FileAsset>): Promise<void>; 3530 3531Adds 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. 3532 3533**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 3534 3535**System capability**: SystemCapability.FileManagement.UserFileManager.Core 3536 3537**Parameters** 3538 3539| Name | Type | Mandatory| Description | 3540| -------- | ------------------------- | ---- | ---------- | 3541| assets | Array<[FileAsset](#fileasset)> | Yes | Array of the image and video assets to add.| 3542 3543**Return value** 3544 3545| Type | Description | 3546| --------------------------------------- | ----------------- | 3547|Promise<void> | Promise that returns no value.| 3548 3549**Error codes** 3550 3551For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 3552 3553| ID| Error Message| 3554| -------- | ---------------------------------------- | 3555| 13900020 | if PhotoAssets is invalid. | 3556 3557**Example** 3558 3559```ts 3560import dataSharePredicates from '@ohos.data.dataSharePredicates'; 3561import { BusinessError } from '@ohos.base'; 3562 3563async function example() { 3564 try { 3565 console.info('addPhotoAssetsDemoPromise'); 3566 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3567 let fetchOption: userFileManager.FetchOptions = { 3568 fetchColumns: [], 3569 predicates: predicates 3570 }; 3571 let albumFetchResult: userFileManager.FetchResult<userFileManager.Album> = await mgr.getAlbums(userFileManager.AlbumType.USER, userFileManager.AlbumSubType.USER_GENERIC); 3572 let album: userFileManager.Album = await albumFetchResult.getFirstObject(); 3573 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await mgr.getPhotoAssets(fetchOption); 3574 let asset: userFileManager.FileAsset = await fetchResult.getFirstObject(); 3575 album.addPhotoAssets([asset]).then(() => { 3576 console.info('album addPhotoAssets successfully'); 3577 }).catch((err: BusinessError) => { 3578 console.error('album addPhotoAssets failed with error: ' + err); 3579 }); 3580 } catch (err) { 3581 console.error('addPhotoAssetsDemoPromise failed with error: ' + err); 3582 } 3583} 3584``` 3585 3586### removePhotoAssets<sup>10+</sup> 3587 3588removePhotoAssets(assets: Array<FileAsset>, callback: AsyncCallback<void>): void; 3589 3590Removes image and video assets from an album. The album and file resources must exist. This API uses an asynchronous callback to return the result. 3591 3592**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 3593 3594**System capability**: SystemCapability.FileManagement.UserFileManager.Core 3595 3596**Parameters** 3597 3598| Name | Type | Mandatory| Description | 3599| -------- | ------------------------- | ---- | ---------- | 3600| assets | Array<[FileAsset](#fileasset)> | Yes | Array of the image and video assets to remove.| 3601| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 3602 3603**Error codes** 3604 3605For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 3606 3607| ID| Error Message| 3608| -------- | ---------------------------------------- | 3609| 13900020 | if PhotoAssets is invalid. | 3610 3611**Example** 3612 3613```ts 3614import dataSharePredicates from '@ohos.data.dataSharePredicates'; 3615 3616async function example() { 3617 try { 3618 console.info('removePhotoAssetsDemoCallback'); 3619 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3620 let fetchOption: userFileManager.FetchOptions = { 3621 fetchColumns: [], 3622 predicates: predicates 3623 }; 3624 let albumFetchResult: userFileManager.FetchResult<userFileManager.Album> = await mgr.getAlbums(userFileManager.AlbumType.USER, userFileManager.AlbumSubType.USER_GENERIC); 3625 let album: userFileManager.Album = await albumFetchResult.getFirstObject(); 3626 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await album.getPhotoAssets(fetchOption); 3627 let asset: userFileManager.FileAsset = await fetchResult.getFirstObject(); 3628 album.removePhotoAssets([asset], (err) => { 3629 if (err === undefined) { 3630 console.info('album removePhotoAssets successfully'); 3631 } else { 3632 console.error('album removePhotoAssets failed with error: ' + err); 3633 } 3634 }); 3635 } catch (err) { 3636 console.error('removePhotoAssetsDemoCallback failed with error: ' + err); 3637 } 3638} 3639``` 3640 3641### removePhotoAssets<sup>10+</sup> 3642 3643removePhotoAssets(assets: Array<FileAsset>): Promise<void>; 3644 3645Removes image and video assets from an album. The album and file resources must exist. This API uses a promise to return the result. 3646 3647**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 3648 3649**System capability**: SystemCapability.FileManagement.UserFileManager.Core 3650 3651**Parameters** 3652 3653| Name | Type | Mandatory| Description | 3654| -------- | ------------------------- | ---- | ---------- | 3655| assets | Array<[FileAsset](#fileasset)> | Yes | Array of the image and video assets to remove.| 3656 3657**Return value** 3658 3659| Type | Description | 3660| --------------------------------------- | ----------------- | 3661|Promise<void> | Promise that returns no value.| 3662 3663**Error codes** 3664 3665For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 3666 3667| ID| Error Message| 3668| -------- | ---------------------------------------- | 3669| 13900020 | if PhotoAssets is invalid. | 3670 3671**Example** 3672 3673```ts 3674import dataSharePredicates from '@ohos.data.dataSharePredicates'; 3675import { BusinessError } from '@ohos.base'; 3676 3677async function example() { 3678 try { 3679 console.info('removePhotoAssetsDemoPromise'); 3680 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3681 let fetchOption: userFileManager.FetchOptions = { 3682 fetchColumns: [], 3683 predicates: predicates 3684 }; 3685 let albumFetchResult: userFileManager.FetchResult<userFileManager.Album> = await mgr.getAlbums(userFileManager.AlbumType.USER, userFileManager.AlbumSubType.USER_GENERIC); 3686 let album: userFileManager.Album = await albumFetchResult.getFirstObject(); 3687 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await album.getPhotoAssets(fetchOption); 3688 let asset: userFileManager.FileAsset = await fetchResult.getFirstObject(); 3689 album.removePhotoAssets([asset]).then(() => { 3690 console.info('album removePhotoAssets successfully'); 3691 }).catch((err: BusinessError) => { 3692 console.error('album removePhotoAssets failed with error: ' + err); 3693 }); 3694 } catch (err) { 3695 console.error('removePhotoAssetsDemoPromise failed with error: ' + err); 3696 } 3697} 3698``` 3699 3700### recoverPhotoAssets<sup>10+</sup> 3701 3702recoverPhotoAssets(assets: Array<FileAsset>, callback: AsyncCallback<void>): void; 3703 3704Recovers image or video assets from the recycle bin. Before the operation, ensure that the image or video assets exist in the recycle bin. This API uses an asynchronous callback to return the result. 3705 3706**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 3707 3708**System capability**: SystemCapability.FileManagement.UserFileManager.Core 3709 3710**Parameters** 3711 3712| Name | Type | Mandatory| Description | 3713| -------- | ------------------------- | ---- | ---------- | 3714| assets | Array<[FileAsset](#fileasset)> | Yes | Array of the image or video assets to recover.| 3715| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 3716 3717**Error codes** 3718 3719For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 3720 3721| ID| Error Message| 3722| -------- | ---------------------------------------- | 3723| 13900020 | if PhotoAssets is invalid. | 3724 3725**Example** 3726 3727```ts 3728import dataSharePredicates from '@ohos.data.dataSharePredicates'; 3729 3730async function example() { 3731 try { 3732 console.info('recoverPhotoAssetsDemoCallback'); 3733 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3734 let fetchOption: userFileManager.FetchOptions = { 3735 fetchColumns: [], 3736 predicates: predicates 3737 }; 3738 let albumFetchResult: userFileManager.FetchResult<userFileManager.Album> = await mgr.getAlbums(userFileManager.AlbumType.SYSTEM, userFileManager.AlbumSubType.TRASH); 3739 let album: userFileManager.Album = await albumFetchResult.getFirstObject(); 3740 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await album.getPhotoAssets(fetchOption); 3741 let asset: userFileManager.FileAsset = await fetchResult.getFirstObject(); 3742 album.recoverPhotoAssets([asset], (err) => { 3743 if (err === undefined) { 3744 console.info('album recoverPhotoAssets successfully'); 3745 } else { 3746 console.error('album recoverPhotoAssets failed with error: ' + err); 3747 } 3748 }); 3749 } catch (err) { 3750 console.error('recoverPhotoAssetsDemoCallback failed with error: ' + err); 3751 } 3752} 3753``` 3754 3755### recoverPhotoAssets<sup>10+</sup> 3756 3757recoverPhotoAssets(assets: Array<FileAsset>): Promise<void>; 3758 3759Recovers image or video assets from the recycle bin. Before the operation, ensure that the image or video assets exist in the recycle bin. This API uses a promise to return the result. 3760 3761**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 3762 3763**System capability**: SystemCapability.FileManagement.UserFileManager.Core 3764 3765**Parameters** 3766 3767| Name | Type | Mandatory| Description | 3768| -------- | ------------------------- | ---- | ---------- | 3769| assets | Array<[FileAsset](#fileasset)> | Yes | Array of the image or video assets to recover.| 3770 3771**Return value** 3772 3773| Type | Description | 3774| --------------------------------------- | ----------------- | 3775|Promise<void> | Promise that returns no value.| 3776 3777**Error codes** 3778 3779For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 3780 3781| ID| Error Message| 3782| -------- | ---------------------------------------- | 3783| 13900020 | if PhotoAssets is invalid. | 3784 3785**Example** 3786 3787```ts 3788import dataSharePredicates from '@ohos.data.dataSharePredicates'; 3789import { BusinessError } from '@ohos.base'; 3790 3791async function example() { 3792 try { 3793 console.info('recoverPhotoAssetsDemoPromise'); 3794 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3795 let fetchOption: userFileManager.FetchOptions = { 3796 fetchColumns: [], 3797 predicates: predicates 3798 }; 3799 let albumFetchResult: userFileManager.FetchResult<userFileManager.Album> = await mgr.getAlbums(userFileManager.AlbumType.SYSTEM, userFileManager.AlbumSubType.TRASH); 3800 let album: userFileManager.Album = await albumFetchResult.getFirstObject(); 3801 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await album.getPhotoAssets(fetchOption); 3802 let asset: userFileManager.FileAsset = await fetchResult.getFirstObject(); 3803 album.recoverPhotoAssets([asset]).then(() => { 3804 console.info('album recoverPhotoAssets successfully'); 3805 }).catch((err: BusinessError) => { 3806 console.error('album recoverPhotoAssets failed with error: ' + err); 3807 }); 3808 } catch (err) { 3809 console.error('recoverPhotoAssetsDemoPromise failed with error: ' + err); 3810 } 3811} 3812``` 3813 3814### deletePhotoAssets<sup>10+</sup> 3815 3816deletePhotoAssets(assets: Array<FileAsset>, callback: AsyncCallback<void>): void; 3817 3818Deletes image or video assets from the recycle bin. Before the operation, ensure that the image or video assets exist in the recycle bin. This API uses an asynchronous callback to return the result. 3819 3820**CAUTION**: This operation is irreversible. The file assets deleted cannot be restored. Exercise caution when performing this operation. 3821 3822**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 3823 3824**System capability**: SystemCapability.FileManagement.UserFileManager.Core 3825 3826**Parameters** 3827 3828| Name | Type | Mandatory| Description | 3829| -------- | ------------------------- | ---- | ---------- | 3830| assets | Array<[FileAsset](#fileasset)> | Yes | Array of the image or video assets to delete.| 3831| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 3832 3833**Error codes** 3834 3835For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 3836 3837| ID| Error Message| 3838| -------- | ---------------------------------------- | 3839| 13900020 | if PhotoAssets is invalid. | 3840 3841**Example** 3842 3843```ts 3844import dataSharePredicates from '@ohos.data.dataSharePredicates'; 3845 3846async function example() { 3847 try { 3848 console.info('deletePhotoAssetsDemoCallback'); 3849 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3850 let fetchOption: userFileManager.FetchOptions = { 3851 fetchColumns: [], 3852 predicates: predicates 3853 }; 3854 let albumFetchResult: userFileManager.FetchResult<userFileManager.Album> = await mgr.getAlbums(userFileManager.AlbumType.SYSTEM, userFileManager.AlbumSubType.TRASH); 3855 let album: userFileManager.Album = await albumFetchResult.getFirstObject(); 3856 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await album.getPhotoAssets(fetchOption); 3857 let asset: userFileManager.FileAsset = await fetchResult.getFirstObject(); 3858 album.deletePhotoAssets([asset], (err) => { 3859 if (err === undefined) { 3860 console.info('album deletePhotoAssets successfully'); 3861 } else { 3862 console.error('album deletePhotoAssets failed with error: ' + err); 3863 } 3864 }); 3865 } catch (err) { 3866 console.error('deletePhotoAssetsDemoCallback failed with error: ' + err); 3867 } 3868} 3869``` 3870 3871### deletePhotoAssets<sup>10+</sup> 3872 3873deletePhotoAssets(assets: Array<FileAsset>): Promise<void>; 3874 3875Deletes image or video assets from the recycle bin. Before the operation, ensure that the image or video assets exist in the recycle bin. This API uses a promise to return the result. 3876 3877**CAUTION**: This operation is irreversible. The file assets deleted cannot be restored. Exercise caution when performing this operation. 3878 3879**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 3880 3881**System capability**: SystemCapability.FileManagement.UserFileManager.Core 3882 3883**Parameters** 3884 3885| Name | Type | Mandatory| Description | 3886| -------- | ------------------------- | ---- | ---------- | 3887| assets | Array<[FileAsset](#fileasset)> | Yes | Array of the image or video assets to delete.| 3888 3889**Return value** 3890 3891| Type | Description | 3892| --------------------------------------- | ----------------- | 3893|Promise<void> | Promise that returns no value.| 3894 3895**Error codes** 3896 3897For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 3898 3899| ID| Error Message| 3900| -------- | ---------------------------------------- | 3901| 13900020 | if PhotoAssets is invalid. | 3902 3903**Example** 3904 3905```ts 3906import dataSharePredicates from '@ohos.data.dataSharePredicates'; 3907import { BusinessError } from '@ohos.base'; 3908 3909async function example() { 3910 try { 3911 console.info('deletePhotoAssetsDemoPromise'); 3912 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3913 let fetchOption: userFileManager.FetchOptions = { 3914 fetchColumns: [], 3915 predicates: predicates 3916 }; 3917 let albumFetchResult: userFileManager.FetchResult<userFileManager.Album> = await mgr.getAlbums(userFileManager.AlbumType.SYSTEM, userFileManager.AlbumSubType.TRASH); 3918 let album: userFileManager.Album = await albumFetchResult.getFirstObject(); 3919 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await album.getPhotoAssets(fetchOption); 3920 let asset: userFileManager.FileAsset = await fetchResult.getFirstObject(); 3921 album.deletePhotoAssets([asset]).then(() => { 3922 console.info('album deletePhotoAssets successfully'); 3923 }).catch((err: BusinessError) => { 3924 console.error('album deletePhotoAssets failed with error: ' + err); 3925 }); 3926 } catch (err) { 3927 console.error('deletePhotoAssetsDemoPromise failed with error: ' + err); 3928 } 3929} 3930``` 3931 3932## PrivateAlbum 3933 3934Provides APIs for managing the system albums. 3935 3936This API will be discarded. Use [Album](#album) instead. 3937 3938### Attributes 3939 3940**System capability**: SystemCapability.FileManagement.UserFileManager.Core 3941 3942| Name | Type | Readable | Writable | Description | 3943| ------------ | ------ | ---- | ---- | ------- | 3944| albumName | string | Yes | Yes | Name of the album. | 3945| albumUri | string | Yes | No | URI of the album. | 3946| dateModified | number | Yes | No | Date when the album was last modified. | 3947| count | number | Yes | No | Number of files in the album.| 3948| coverUri | string | Yes | No | URI of the cover file of the album.| 3949 3950### getPhotoAssets 3951 3952getPhotoAssets(options: FetchOptions, callback: AsyncCallback<FetchResult<FileAsset>>): void; 3953 3954Obtains image and video assets from a system album. This API uses an asynchronous callback to return the result. 3955 3956This API will be deprecated. Use [Album.getPhotoAssets](#getphotoassets-2) instead. 3957 3958**Required permissions**: ohos.permission.READ_IMAGEVIDEO 3959 3960**System capability**: SystemCapability.FileManagement.UserFileManager.Core 3961 3962**Parameters** 3963 3964| Name | Type | Mandatory| Description | 3965| -------- | ------------------------- | ---- | ---------- | 3966| options | [FetchOptions](#fetchoptions) | Yes | Options for fetching the image and video assets.| 3967| callback | AsyncCallback<[FetchResult](#fetchresult)<[FileAsset](#fileasset)>> | Yes | Callback invoked to return the image and video assets obtained.| 3968 3969**Error codes** 3970 3971For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 3972 3973| ID| Error Message| 3974| -------- | ---------------------------------------- | 3975| 13900020 | if type options is not FetchOptions. | 3976 3977**Example** 3978 3979```ts 3980import dataSharePredicates from '@ohos.data.dataSharePredicates'; 3981 3982async function example() { 3983 console.info('privateAlbumGetFileAssetsDemoCallback'); 3984 let albumList: userFileManager.FetchResult<userFileManager.PrivateAlbum> = await mgr.getPrivateAlbum(userFileManager.PrivateAlbumType.TYPE_TRASH); 3985 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3986 let fetchOption: userFileManager.FetchOptions = { 3987 fetchColumns: [], 3988 predicates: predicates 3989 }; 3990 const trashAlbum: userFileManager.PrivateAlbum = await albumList.getFirstObject(); 3991 trashAlbum.getPhotoAssets(fetchOption, (err, fetchResult) => { 3992 if (fetchResult != undefined) { 3993 let count = fetchResult.getCount(); 3994 console.info('fetchResult.count = ', count); 3995 } else { 3996 console.error('getFileAssets failed, message = ', err); 3997 } 3998 }); 3999} 4000 4001``` 4002 4003### getPhotoAssets 4004 4005getPhotoAssets(options: FetchOptions): Promise<FetchResult<FileAsset>>; 4006 4007Obtains image and video assets from a system album. This API uses a promise to return the result. 4008 4009This API will be deprecated. Use [Album.getPhotoAssets](#getphotoassets-3) instead. 4010 4011**Required permissions**: ohos.permission.READ_IMAGEVIDEO 4012 4013**System capability**: SystemCapability.FileManagement.UserFileManager.Core 4014 4015**Parameters** 4016 4017| Name | Type | Mandatory| Description | 4018| -------- | ------------------------- | ---- | ---------- | 4019| options | [FetchOptions](#fetchoptions) | Yes | Options for fetching the image and video assets.| 4020 4021**Return value** 4022 4023| Type | Description | 4024| --------------------------------------- | ----------------- | 4025| Promise:[FetchResult](#fetchresult)<[FileAsset](#fileasset)>| Promise used to return the image and video assets obtained.| 4026 4027**Error codes** 4028 4029For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 4030 4031| ID| Error Message| 4032| -------- | ---------------------------------------- | 4033| 13900020 | if type options is not FetchOptions. | 4034 4035**Example** 4036 4037```ts 4038import dataSharePredicates from '@ohos.data.dataSharePredicates'; 4039 4040async function example() { 4041 console.info('privateAlbumGetFileAssetsDemoPromise'); 4042 let albumList: userFileManager.FetchResult<userFileManager.PrivateAlbum> = await mgr.getPrivateAlbum(userFileManager.PrivateAlbumType.TYPE_TRASH); 4043 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4044 let fetchOption: userFileManager.FetchOptions = { 4045 fetchColumns: [], 4046 predicates: predicates 4047 }; 4048 const trashAlbum: userFileManager.PrivateAlbum = await albumList.getFirstObject(); 4049 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await trashAlbum.getPhotoAssets(fetchOption); 4050 let count = fetchResult.getCount(); 4051 console.info('fetchResult.count = ', count); 4052} 4053``` 4054 4055### delete 4056 4057delete(uri: string, callback: AsyncCallback<void>): void; 4058 4059Deletes files from a system album. 4060 4061This API will be deprecated. Use [Album.deletePhotoAssets](#deletephotoassets10) instead. 4062 4063**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.READ_AUDIO, and ohos.permission.WRITE_AUDIO 4064 4065**System capability**: SystemCapability.FileManagement.UserFileManager.Core 4066 4067**Parameters** 4068 4069| Name | Type | Mandatory| Description | 4070| -------- | ------------------------- | ---- | ---------- | 4071| uri | string | Yes | URI of the album.| 4072| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 4073 4074**Example** 4075 4076```ts 4077import dataSharePredicates from '@ohos.data.dataSharePredicates'; 4078 4079async function example() { 4080 console.info('privateAlbumDeleteCallback'); 4081 let albumList: userFileManager.FetchResult<userFileManager.PrivateAlbum> = await mgr.getPrivateAlbum(userFileManager.PrivateAlbumType.TYPE_TRASH); 4082 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4083 let fetchOption: userFileManager.FetchOptions = { 4084 fetchColumns: [], 4085 predicates: predicates 4086 }; 4087 let trashAlbum: userFileManager.PrivateAlbum = await albumList.getFirstObject(); 4088 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await trashAlbum.getPhotoAssets(fetchOption); 4089 let fileAsset: userFileManager.FileAsset = await fetchResult.getFirstObject(); 4090 let deleteFileUri = fileAsset.uri; 4091 trashAlbum.delete(deleteFileUri, (err) => { 4092 if (err != undefined) { 4093 console.error('trashAlbum.delete failed, message = ', err); 4094 } else { 4095 console.info('trashAlbum.delete successfully'); 4096 } 4097 }); 4098} 4099``` 4100 4101### delete 4102 4103delete(uri: string): Promise<void>; 4104 4105Deletes files from a system album. 4106 4107This API will be deprecated. Use [Album.deletePhotoAssets](#deletephotoassets10) instead. 4108 4109**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.READ_AUDIO, and ohos.permission.WRITE_AUDIO 4110 4111**System capability**: SystemCapability.FileManagement.UserFileManager.Core 4112 4113**Parameters** 4114 4115| Name | Type | Mandatory| Description | 4116| -------- | ------------------------- | ---- | ---------- | 4117| uri | string | Yes | URI of the album.| 4118 4119**Return value** 4120 4121| Type | Description | 4122| --------------------------------------- | ----------------- | 4123| Promise<void>| Promise that returns no value.| 4124 4125**Example** 4126 4127```ts 4128import dataSharePredicates from '@ohos.data.dataSharePredicates'; 4129import { BusinessError } from '@ohos.base'; 4130 4131async function example() { 4132 console.info('privateAlbumDeleteDemoPromise'); 4133 let albumListlet albumList: userFileManager.FetchResult<userFileManager.PrivateAlbum>let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4134 let fetchOption: userFileManager.FetchOptions = { 4135 fetchColumns: [], 4136 predicates: predicates 4137 }; 4138 let trashAlbum: userFileManager.PrivateAlbum = await albumList.getFirstObject(); 4139 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await trashAlbum.getPhotoAssets(fetchOption); 4140 let fileAsset: userFileManager.FileAsset = await fetchResult.getFirstObject(); 4141 let deleteFileUri = fileAsset.uri; 4142 trashAlbum.delete(deleteFileUri).then(() => { 4143 console.info('trashAlbum.delete successfully'); 4144 }).catch((err: BusinessError) => { 4145 console.error('trashAlbum.delete failed, message = ', err); 4146 }); 4147} 4148``` 4149 4150### recover 4151 4152recover(uri: string, callback: AsyncCallback<void>): void; 4153 4154Recovers files in a system album. 4155 4156This API will be deprecated. Use [Album.recoverPhotoAssets](#recoverphotoassets10) instead. 4157 4158**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.READ_AUDIO, and ohos.permission.WRITE_AUDIO 4159 4160**System capability**: SystemCapability.FileManagement.UserFileManager.Core 4161 4162**Parameters** 4163 4164| Name | Type | Mandatory| Description | 4165| -------- | ------------------------- | ---- | ---------- | 4166| uri | string | Yes | URI of the album.| 4167| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 4168 4169**Example** 4170 4171```ts 4172import dataSharePredicates from '@ohos.data.dataSharePredicates'; 4173 4174async function example() { 4175 console.info('privateAlbumRecoverDemoCallback'); 4176 let albumList: userFileManager.FetchResult<userFileManager.PrivateAlbum> = await mgr.getPrivateAlbum(userFileManager.PrivateAlbumType.TYPE_TRASH); 4177 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4178 let fetchOption: userFileManager.FetchOptions = { 4179 fetchColumns: [], 4180 predicates: predicates 4181 }; 4182 let trashAlbum: userFileManager.PrivateAlbum = await albumList.getFirstObject(); 4183 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await trashAlbum.getPhotoAssets(fetchOption); 4184 let fileAsset: userFileManager.FileAsset = await fetchResult.getFirstObject(); 4185 let recoverFileUri: string = fileAsset.uri; 4186 trashAlbum.recover(recoverFileUri, (err) => { 4187 if (err != undefined) { 4188 console.error('trashAlbum.recover failed, message = ', err); 4189 } else { 4190 console.info('trashAlbum.recover successfully'); 4191 } 4192 }); 4193} 4194``` 4195 4196### recover 4197 4198recover(uri: string): Promise<void>; 4199 4200Recovers files in a system album. 4201 4202This API will be deprecated. Use [Album.recoverPhotoAssets](#recoverphotoassets10) instead. 4203 4204**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.READ_AUDIO, and ohos.permission.WRITE_AUDIO 4205 4206**System capability**: SystemCapability.FileManagement.UserFileManager.Core 4207 4208**Parameters** 4209 4210| Name | Type | Mandatory| Description | 4211| -------- | ------------------------- | ---- | ---------- | 4212| uri | string | Yes | URI of the album.| 4213 4214**Return value** 4215 4216| Type | Description | 4217| --------------------------------------- | ----------------- | 4218| Promise<void>| Promise that returns no value.| 4219 4220**Example** 4221 4222```ts 4223import dataSharePredicates from '@ohos.data.dataSharePredicates'; 4224import { BusinessError } from '@ohos.base'; 4225 4226async function example() { 4227 console.info('privateAlbumRecoverDemoPromise'); 4228 let albumList: userFileManager.FetchResult<userFileManager.PrivateAlbum> = await mgr.getPrivateAlbum(userFileManager.PrivateAlbumType.TYPE_TRASH); 4229 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4230 let fetchOption: userFileManager.FetchOptions = { 4231 fetchColumns: [], 4232 predicates: predicates 4233 }; 4234 let trashAlbum: userFileManager.PrivateAlbum = await albumList.getFirstObject(); 4235 let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await trashAlbum.getPhotoAssets(fetchOption); 4236 let fileAsset: userFileManager.FileAsset = await fetchResult.getFirstObject(); 4237 let recoverFileUri: string = fileAsset.uri; 4238 trashAlbum.recover(recoverFileUri).then(() => { 4239 console.info('trashAlbum.recover successfully'); 4240 }).catch((err: BusinessError) => { 4241 console.error('trashAlbum.recover failed, message = ', err); 4242 }); 4243} 4244``` 4245 4246## MemberType 4247 4248Enumerates the member types. 4249 4250**System capability**: SystemCapability.FileManagement.UserFileManager.Core 4251 4252| Name | Type| Readable | Writable | Description | 4253| ----- | ---- | ---- | ---- | ---- | 4254| number | number | Yes| Yes| The member is a number.| 4255| string | string | Yes| Yes| The member is a string.| 4256| boolean | boolean | Yes| Yes| The member is a Boolean value.| 4257 4258## ChangeEvent 4259 4260Enumerates the type of changes to observe. 4261 4262**System capability**: SystemCapability.FileManagement.UserFileManager.Core 4263 4264| Name | Type| Readable | Writable | Description| 4265| ----- | ---- | ---- | ---- | ---- | 4266| deviceChange | string | Yes| Yes| Device change.| 4267| albumChange | string | Yes| Yes| Album change.| 4268| imageChange | string | Yes| Yes| Image change.| 4269| audioChange | string | Yes| Yes| Audio change.| 4270| videoChange | string | Yes| Yes| Video change.| 4271| remoteFileChange | string | Yes| Yes| Remote file change.| 4272 4273## PeerInfo 4274 4275Defines information about a registered device. 4276 4277**System capability**: SystemCapability.FileManagement.UserFileManager.DistributedCore 4278 4279| Name | Type | Readable| Writable| Description | 4280| ---------- | -------------------------- | ---- | ---- | ---------------- | 4281| deviceName | string | Yes | No | Name of the registered device. | 4282| networkId | string | Yes | No | Network ID of the registered device.| 4283| isOnline | boolean | Yes | No | Whether the registered device is online. | 4284 4285## FileType 4286 4287Enumerates media file types. 4288 4289**System capability**: SystemCapability.FileManagement.UserFileManager.Core 4290 4291| Name | Value| Description| 4292| ----- | ---- | ---- | 4293| IMAGE | 1 | Image.| 4294| VIDEO | 2 | Video.| 4295| AUDIO | 3 | Audio.| 4296 4297## PhotoSubType<sup>10+</sup> 4298 4299Enumerates the [FileAsset](#fileasset) types. 4300 4301**System capability**: SystemCapability.FileManagement.UserFileManager.Core 4302 4303| Name | Value| Description| 4304| ----- | ---- | ---- | 4305| DEFAULT | 0 | Default (photo) type.| 4306| SCREENSHOT | 1 | Screenshots and screen recording files.| 4307| CAMERA | 2 | Photos and videos taken by a camera.| 4308 4309## PositionType<sup>10+</sup> 4310 4311Enumerates the file location. 4312 4313**System capability**: SystemCapability.FileManagement.UserFileManager.Core 4314 4315| Name | Value| Description| 4316| ----- | ---- | ---- | 4317| LOCAL | 1 | Stored only on a local device.| 4318| CLOUD | 2 | Stored only on the cloud.| 4319| BOTH | 3 | Stored both on a local device and the cloud.| 4320 4321## AlbumType<sup>10+</sup> 4322 4323Enumerates the album types. 4324 4325**System capability**: SystemCapability.FileManagement.UserFileManager.Core 4326 4327| Name | Value| Description| 4328| ----- | ---- | ---- | 4329| USER | 0 | User album.| 4330| SYSTEM | 1024 | System album.| 4331 4332## AlbumSubType<sup>10+</sup> 4333 4334Enumerate the album subtypes. 4335 4336**System capability**: SystemCapability.FileManagement.UserFileManager.Core 4337 4338| Name | Value| Description| 4339| ----- | ---- | ---- | 4340| USER_GENERIC | 1 | User album.| 4341| FAVORITE | 1025 | Favorites.| 4342| VIDEO | 1026 | Video album.| 4343| HIDDEN | 1027 | Hidden album.| 4344| TRASH | 1028 | Recycle bin.| 4345| SCREENSHOT | 1029 | Album for screenshots and screen recording files.| 4346| CAMERA | 1030 | Album for photos and videos taken by the camera.| 4347| ANY | 2147483647 | Any album.| 4348 4349## PrivateAlbumType 4350 4351Enumerates the system album types. 4352 4353This API will be deprecated. Use [AlbumType](#albumtype10) and [AlbumSubType](#albumsubtype10) instead. 4354 4355**System capability**: SystemCapability.FileManagement.UserFileManager.Core 4356 4357| Name | Value| Description | 4358| ----- | ---- | ---- | 4359| TYPE_FAVORITE | 0 | Favorites.| 4360| TYPE_TRASH | 1 | Recycle bin.| 4361 4362## AudioKey 4363 4364Defines the key information about an audio file. 4365 4366**System capability**: SystemCapability.FileManagement.UserFileManager.Core 4367 4368| Name | Value | Description | 4369| ------------- | ------------------- | ---------------------------------------------------------- | 4370| URI | uri | URI of the file. | 4371| DISPLAY_NAME | display_name | File name displayed. | 4372| DATE_ADDED | date_added | Date when the file was added. The value is the number of seconds elapsed since the Epoch time. | 4373| 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.| 4374| TITLE | title | Title in the file. | 4375| ARTIST | artist | Author of the file. | 4376| AUDIOALBUM | audio_album | Audio album. | 4377| DURATION | duration | Duration, in ms. | 4378| FAVORITE | favorite | Whether the file is added to favorites. | 4379 4380## ImageVideoKey 4381 4382Defines the key information about an image or video file. 4383 4384**System capability**: SystemCapability.FileManagement.UserFileManager.Core 4385 4386| Name | Value | Description | 4387| ------------- | ------------------- | ---------------------------------------------------------- | 4388| URI | uri | URI of the file. | 4389| FILE_TYPE | file_type | Type of the file. | 4390| DISPLAY_NAME | display_name | File name displayed. | 4391| DATE_ADDED | date_added | Date when the file was added. The value is the number of seconds elapsed since the Epoch time. | 4392| 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.| 4393| TITLE | title | Title of the file. | 4394| DURATION | duration | Duration, in ms. | 4395| WIDTH | width | Image width, in pixels. | 4396| HEIGHT | height | Image height, in pixels. | 4397| DATE_TAKEN | date_taken | Date when the file (photo) was taken. The value is the number of seconds elapsed since the Epoch time. | 4398| ORIENTATION | orientation | Orientation of the image file. | 4399| FAVORITE | favorite | Whether the file is added to favorites. | 4400| POSITION<sup>10+</sup> | position | File location type. | 4401| DATE_TRASHED<sup>10+</sup> | date_trashed | Date when the file was deleted. The value is the number of seconds between the time when the file is deleted and January 1, 1970. | 4402| HIDDEN<sup>10+</sup> | hidden | Whether the file is hidden. | 4403| CAMERA_SHOT_KEY<sup>10+</sup> | camera_shot_key | Key for the Ultra Snapshot feature, which allows the camera to take photos or record videos with the screen off. (This parameter is available only for the system camera, and the key value is defined by the system camera.) | 4404| USER_COMMENT<sup>10+</sup> | user_comment | User comment information. | 4405 4406## AlbumKey 4407 4408Defines the key album information. 4409 4410**System capability**: SystemCapability.FileManagement.UserFileManager.Core 4411 4412| Name | Value | Description | 4413| ------------- | ------------------- | ---------------------------------------------------------- | 4414| URI | uri | URI of the album. | 4415| FILE_TYPE | file_type | Type of the file. | 4416| ALBUM_NAME | album_name | Name of the album. | 4417| DATE_ADDED | date_added | Date when the album was added. The value is the number of seconds elapsed since the Epoch time. | 4418| DATE_MODIFIED | date_modified | Date when the album file content (not the album name) was last modified. The value is the number of seconds elapsed since the Epoch time.| 4419 4420## PhotoCreateOptions<sup>10+</sup> 4421 4422Options for creating an image or video asset. 4423 4424**System capability**: SystemCapability.FileManagement.UserFileManager.Core 4425 4426| Name | Type | Mandatory| Description | 4427| ---------------------- | ------------------- | ---- | ------------------------------------------------ | 4428| subType | [PhotoSubType](#photosubtype10) | No | Subtype of the image or video. | 4429| cameraShotKey | string | No | Key for the Ultra Snapshot feature, which allows the camera to take photos or record videos with the screen off. (This parameter is available only for the system camera, and the key value is defined by the system camera.) | 4430 4431## FetchOptions 4432 4433Defines the options for fetching media files. 4434 4435**System capability**: SystemCapability.FileManagement.UserFileManager.Core 4436 4437| Name | Type | Readable| Writable| Description | 4438| ---------------------- | ------------------- | ---- |---- | ------------------------------------------------ | 4439| fetchColumns | Array<string> | Yes | Yes | Column names used for retrieval. If this parameter is left empty, the media files are fetched by URI, name, and file type by default. The specific field names are subject to the definition of the search object. Example:<br>fetchColumns: ['uri', 'title']| 4440| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md) | Yes | Yes | Predicates that specify the fetch criteria.| 4441 4442## AlbumFetchOptions 4443 4444Defines the options for fetching an album. 4445 4446**System capability**: SystemCapability.FileManagement.UserFileManager.Core 4447 4448| Name | Type | Readable| Writable| Description | 4449| ---------------------- | ------------------- | ---- |---- | ------------------------------------------------ | 4450| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md) | Yes | Yes | Predicates that specify the fetch criteria.| 4451 4452## ChangeData<sup>10+</sup> 4453 4454Defines the return value of the listener callback. 4455 4456**System capability**: SystemCapability.FileManagement.UserFileManager.Core 4457 4458| Name | Type | Readable| Writable| Description | 4459| ------- | --------------------------- | ---- | ---- | ------------------------------------------------------------ | 4460| type | [NotifyType](#notifytype10) | Yes | No | Notification type. | 4461| uris | Array<string> | Yes | No | Array of all file asset or album URIs with the same [NotifyType](#notifytype10).| 4462| subUris | Array<string> | Yes | No | URIs of the changed files in the album. | 4463 4464## NotifyType<sup>10+</sup> 4465 4466Enumerates the notification event types. 4467 4468**System capability**: SystemCapability.FileManagement.UserFileManager.Core 4469 4470| Name | Value | Description | 4471| ------------------------- | ---- | -------------------------------- | 4472| NOTIFY_ADD | 0 | A file asset or album is added. | 4473| NOTIFY_UPDATE | 1 | A file asset or album is updated. | 4474| NOTIFY_REMOVE | 2 | A file asset or album is removed. | 4475| NOTIFY_ALBUM_ADD_ASSET | 3 | A file asset is added to the album.| 4476| NOTIFY_ALBUM_REMOVE_ASSET | 4 | A file asset is removed from the album.| 4477 4478## DefaultChangeUri<sup>10+</sup> 4479 4480Enumerates the **DefaultChangeUri** subtypes. 4481 4482**System capability**: SystemCapability.FileManagement.UserFileManager.Core 4483 4484| Name | Value | Description | 4485| ----------------- | ----------------------- | ------------------------------------------------------------ | 4486| DEFAULT_PHOTO_URI | file://media/Photo | Default **PhotoAsset** URI. The **PhotoAsset** change notifications are received based on this parameter and **forSubUri{true}**.| 4487| DEFAULT_ALBUM_URI | file://media/PhotoAlbum | Default album URI. Album change notifications are received based on this parameter and **forSubUri{true}**. | 4488| DEFAULT_AUDIO_URI | file://media/Audio | Default **AudioAsset** URI. The **AudioAsset** change notifications are received based on this parameter and **forSubUri{true}**.| 4489