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