• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.filemanagement.userFileManager (User Data Management)
2
3The **userFileManager** module provides user data management capabilities, including accessing and modifying user media data (audio and video clips, images, and files).
4
5> **NOTE**
6>
7> - The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8> - The APIs provided by this module are system APIs.
9
10## Modules to Import
11
12```ts
13import userFileManager from '@ohos.filemanagement.userFileManager';
14```
15
16## userFileManager.getUserFileMgr
17
18getUserFileMgr(context: Context): UserFileManager
19
20Obtains a **UserFileManager** instance. This instance can be used to access and modify user media data (such as audio and video clips, images, and files).
21
22**Model restriction**: This API can be used only in the stage model.
23
24**System capability**: SystemCapability.FileManagement.UserFileManager.Core
25
26**Parameters**
27
28| Name | Type   | Mandatory| Description                      |
29| ------- | ------- | ---- | -------------------------- |
30| context | [Context](js-apis-inner-app-context.md) | Yes  | Context of the ability instance.|
31
32**Return value**
33
34| Type                           | Description   |
35| ----------------------------- | :---- |
36| [UserFileManager](#userfilemanager) | **UserFileManager** instance obtained.|
37
38**Example**
39
40```ts
41// The userFileManager instance obtained is a global object. It is used by default in subsequent operations. If the code snippet is not added, an error will be reported indicating that mgr is not defined.
42const context = getContext(this);
43let mgr = userFileManager.getUserFileMgr(context);
44```
45
46## UserFileManager
47
48### getPhotoAssets
49
50getPhotoAssets(options: FetchOptions, callback: AsyncCallback<FetchResult<FileAsset>>): void;
51
52Obtains image and video assets. This API uses an asynchronous callback to return the result.
53
54**System capability**: SystemCapability.FileManagement.UserFileManager.Core
55
56**Required permissions**: ohos.permission.READ_IMAGEVIDEO
57
58**Parameters**
59
60| Name  | Type                    | Mandatory| Description                     |
61| -------- | ------------------------ | ---- | ------------------------- |
62| options  | [FetchOptions](#fetchoptions)        | Yes  | Options for fetching the image and video assets.             |
63| callback |  AsyncCallback<[FetchResult](#fetchresult)<[FileAsset](#fileasset)>> | Yes  | Callback invoked to return the image and video assets obtained.|
64
65**Example**
66
67```ts
68import dataSharePredicates from '@ohos.data.dataSharePredicates';
69
70async function example() {
71  console.info('getPhotoAssets');
72  let predicates = new dataSharePredicates.DataSharePredicates();
73  let fetchOptions = {
74    fetchColumns: [],
75    predicates: predicates
76  };
77
78  mgr.getPhotoAssets(fetchOptions, async (err, fetchResult) => {
79    if (fetchResult != undefined) {
80      console.info('fetchResult success');
81      let fileAsset = await fetchResult.getFirstObject();
82      if (fileAsset != undefined) {
83        console.info("fileAsset.displayName : " + fileAsset.displayName);
84      }
85    } else {
86      console.error('fetchResult fail' + err);
87    }
88  });
89}
90```
91
92### getPhotoAssets
93
94getPhotoAssets(options: FetchOptions): Promise<FetchResult<FileAsset>>;
95
96Obtains image and video assets. This API uses a promise to return the result.
97
98**System capability**: SystemCapability.FileManagement.UserFileManager.Core
99
100**Required permissions**: ohos.permission.READ_IMAGEVIDEO
101
102**Parameters**
103
104| Name | Type               | Mandatory| Description            |
105| ------- | ------------------- | ---- | ---------------- |
106| options | [FetchOptions](#fetchoptions)   | Yes  | Options for fetching the image and video assets.    |
107
108**Return value**
109
110| Type                       | Description          |
111| --------------------------- | -------------- |
112| Promise<[FetchResult](#fetchresult)<[FileAsset](#fileasset)>> | Promise used to return the image and video assets obtained.|
113
114**Example**
115
116```ts
117import dataSharePredicates from '@ohos.data.dataSharePredicates';
118
119async function example() {
120  console.info('getPhotoAssets');
121  let predicates = new dataSharePredicates.DataSharePredicates();
122  let fetchOptions = {
123    fetchColumns: [],
124    predicates: predicates
125  };
126  try {
127    let fetchResult = await mgr.getPhotoAssets(fetchOptions);
128    if (fetchResult != undefined) {
129      console.info('fetchResult success');
130      let fileAsset = await fetchResult.getFirstObject();
131      if (fileAsset != undefined) {
132        console.info("fileAsset.displayName :" + fileAsset.displayName);
133      }
134    }
135  } catch (err) {
136    console.error('getPhotoAssets failed, message = ', err);
137  }
138}
139```
140
141### createPhotoAsset
142
143createPhotoAsset(displayName: string, albumUri: string, callback: AsyncCallback<FileAsset>): void;
144
145Creates an image or video asset. This API uses an asynchronous callback to return the result.
146
147**System capability**: SystemCapability.FileManagement.UserFileManager.Core
148
149**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
150
151**Parameters**
152
153| Name  | Type                    | Mandatory| Description                     |
154| -------- | ------------------------ | ---- | ------------------------- |
155| displayName  | string        | Yes  | File name of the image or video to create.             |
156| albumUri  | string        | Yes  | URI of the album where the image or video is located.             |
157| callback |  AsyncCallback<[FileAsset](#fileasset)> | Yes  | Callback invoked to return the image or video created.|
158
159**Example**
160
161```ts
162import dataSharePredicates from '@ohos.data.dataSharePredicates';
163
164async function example() {
165  console.info('createPhotoAssetDemo');
166  let predicates = new dataSharePredicates.DataSharePredicates();
167  let fetchOptions = {
168    predicates: predicates
169  };
170  let albums = await mgr.getPhotoAlbums(fetchOptions);
171  let album = await albums.getFirstObject();
172  let testFileName = "testFile" + Date.now() + ".jpg";
173  mgr.createPhotoAsset(testFileName, album.albumUri, (err, fileAsset) => {
174    if (fileAsset != undefined) {
175      console.info('createPhotoAsset file displayName' + fileAsset.displayName);
176      console.info('createPhotoAsset successfully');
177    } else {
178      console.error('createPhotoAsset failed, message = ', err);
179    }
180  });
181}
182```
183
184### createPhotoAsset
185
186createPhotoAsset(displayName: string, callback: AsyncCallback<FileAsset>): void;
187
188Creates an image or video asset. This API uses an asynchronous callback to return the result.
189
190**System capability**: SystemCapability.FileManagement.UserFileManager.Core
191
192**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
193
194**Parameters**
195
196| Name  | Type                    | Mandatory| Description                     |
197| -------- | ------------------------ | ---- | ------------------------- |
198| displayName  | string        | Yes  | File name of the image or video to create.             |
199| callback |  AsyncCallback<[FileAsset](#fileasset)> | Yes  | Callback invoked to return the image or video created.|
200
201**Example**
202
203```ts
204async function example() {
205  console.info('createPhotoAssetDemo');
206  let testFileName = "testFile" + Date.now() + ".jpg";
207  mgr.createPhotoAsset(testFileName, (err, fileAsset) => {
208    if (fileAsset != undefined) {
209      console.info('createPhotoAsset file displayName' + fileAsset.displayName);
210      console.info('createPhotoAsset successfully');
211    } else {
212      console.error('createPhotoAsset failed, message = ', err);
213    }
214  });
215}
216```
217
218### createPhotoAsset
219
220createPhotoAsset(displayName: string, albumUri?: string): Promise<FileAsset>;
221
222Creates an image or video asset. This API uses a promise to return the result.
223
224**System capability**: SystemCapability.FileManagement.UserFileManager.Core
225
226**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
227
228**Parameters**
229
230| Name  | Type                    | Mandatory| Description                     |
231| -------- | ------------------------ | ---- | ------------------------- |
232| displayName  | string        | Yes  | File name of the image or video to create.             |
233| albumUri  | string        | No  | URI of the album where the image or video is located.             |
234
235**Return value**
236
237| Type                       | Description          |
238| --------------------------- | -------------- |
239| Promise<[FileAsset](#fileasset)> | Promise used to return the image or video created.|
240
241**Example**
242
243```ts
244async function example() {
245  console.info('createPhotoAssetDemo');
246  try {
247    let testFileName = "testFile" + Date.now() + ".jpg";
248    let fileAsset = await mgr.createPhotoAsset(testFileName);
249    console.info('createPhotoAsset file displayName' + fileAsset.displayName);
250    console.info('createPhotoAsset successfully');
251  } catch (err) {
252    console.error('createPhotoAsset failed, message = ', err);
253  }
254}
255```
256
257### getPhotoAlbums
258
259getPhotoAlbums(options: AlbumFetchOptions, callback: AsyncCallback<FetchResult<Album>>): void;
260
261Obtains image and video albums. This API uses an asynchronous callback to return the result.
262
263**System capability**: SystemCapability.FileManagement.UserFileManager.Core
264
265**Required permissions**: ohos.permission.READ_IMAGEVIDEO
266
267**Parameters**
268
269| Name  | Type                    | Mandatory| Description                     |
270| -------- | ------------------------ | ---- | ------------------------- |
271| options  | [AlbumFetchOptions](#albumfetchoptions)        | Yes  | Options for fetching the albums.             |
272| callback |  AsyncCallback<[FetchResult](#fetchresult)<[Album](#album)>> | Yes  | Callback invoked to return the albums obtained.|
273
274**Example**
275
276```ts
277import dataSharePredicates from '@ohos.data.dataSharePredicates';
278
279async function example() {
280  console.info('getPhotoAlbumsDemo');
281  let predicates = new dataSharePredicates.DataSharePredicates();
282  let albumFetchOptions = {
283    predicates: predicates
284  };
285
286  mgr.getPhotoAlbums(albumFetchOptions, (err, fetchResult) => {
287    if (fetchResult != undefined) {
288      console.info('albums.count = ' + fetchResult.getCount());
289      fetchResult.getFirstObject((err, album) => {
290        if (album != undefined) {
291          console.info('first album.albumName = ' + album.albumName);
292        } else {
293          console.error('album is undefined, err = ', err);
294        }
295      });
296    } else {
297      console.error('getPhotoAlbums fail, message = ', err);
298    }
299  });
300}
301```
302
303### getPhotoAlbums
304
305getPhotoAlbums(options: AlbumFetchOptions): Promise<FetchResult<Album>>;
306
307Obtains image and video albums. This API uses a promise to return the result.
308
309**System capability**: SystemCapability.FileManagement.UserFileManager.Core
310
311**Required permissions**: ohos.permission.READ_IMAGEVIDEO
312
313**Parameters**
314
315| Name  | Type                    | Mandatory| Description                     |
316| -------- | ------------------------ | ---- | ------------------------- |
317| options  | [AlbumFetchOptions](#albumfetchoptions)        | Yes  | Options for fetching the albums.             |
318
319**Return value**
320
321| Type                       | Description          |
322| --------------------------- | -------------- |
323| Promise<[FetchResult](#fetchresult)<[Album](#album)>> | Promise used to return the albums obtained.|
324
325**Example**
326
327```ts
328import dataSharePredicates from '@ohos.data.dataSharePredicates';
329
330async function example() {
331  console.info('getPhotoAlbumsDemo');
332  let predicates = new dataSharePredicates.DataSharePredicates();
333  let albumFetchOptions = {
334    predicates: predicates
335  };
336  try {
337    let fetchResult = await mgr.getPhotoAlbums(albumFetchOptions);
338    console.info('album.count = ' + fetchResult.getCount());
339    const album = await fetchResult.getFirstObject();
340    console.info('first album.albumName = ' + album.albumName);
341  } catch (err) {
342    console.error('getPhotoAlbums fail, message = ' + err);
343  }
344}
345```
346
347### getPrivateAlbum
348
349getPrivateAlbum(type: PrivateAlbumType, callback: AsyncCallback<FetchResult<PrivateAlbum>>): void;
350
351Obtains the system album. This API uses an asynchronous callback to return the result.
352
353**System capability**: SystemCapability.FileManagement.UserFileManager.Core
354
355**Required permissions**: ohos.permission.READ_IMAGEVIDEO
356
357**Parameters**
358
359| Name  | Type                    | Mandatory| Description                     |
360| -------- | ------------------------ | ---- | ------------------------- |
361| type  | [PrivateAlbumType](#privatealbumtype)        | Yes  | Type of the album to obtain.             |
362| callback |  AsyncCallback<[FetchResult](#fetchresult)<[PrivateAlbum](#privatealbum)>> | Yes  | Callback invoked to return the album obtained.|
363
364**Example**
365
366```ts
367async function example() {
368  console.info('getPrivateAlbumDemo');
369  mgr.getPrivateAlbum(userFileManager.PrivateAlbumType.TYPE_TRASH, async (err, fetchResult) => {
370    if (fetchResult != undefined) {
371      let trashAlbum = await fetchResult.getFirstObject();
372      console.info('first album.albumName = ' + trashAlbum.albumName);
373    } else {
374      console.error('getPrivateAlbum failed. message = ', err);
375    }
376  });
377}
378```
379
380### getPrivateAlbum
381
382getPrivateAlbum(type: PrivateAlbumType): Promise<FetchResult<PrivateAlbum>>;
383
384
385Obtains the system album. This API uses a promise to return the result.
386
387**System capability**: SystemCapability.FileManagement.UserFileManager.Core
388
389**Required permissions**: ohos.permission.READ_IMAGEVIDEO
390
391**Parameters**
392
393| Name  | Type                    | Mandatory| Description                     |
394| -------- | ------------------------ | ---- | ------------------------- |
395| type  | [PrivateAlbumType](#privatealbumtype)        | Yes  | Type of the album to obtain.             |
396
397**Return value**
398
399| Type                       | Description          |
400| --------------------------- | -------------- |
401| Promise<[FetchResult](#fetchresult)<[PrivateAlbum](#privatealbum)>> | Promise used to return the album obtained.|
402
403**Example**
404
405```ts
406async function example() {
407  console.info('getPrivateAlbumDemo');
408  try {
409    let fetchResult = await mgr.getPrivateAlbum(userFileManager.PrivateAlbumType.TYPE_TRASH);
410    let trashAlbum = await fetchResult.getFirstObject();
411    console.info('first album.albumName = ' + trashAlbum.albumName);
412  } catch (err) {
413    console.error('getPrivateAlbum failed. message = ', err);
414  }
415}
416```
417
418### getAudioAssets
419
420getAudioAssets(options: FetchOptions, callback: AsyncCallback<FetchResult<FileAsset>>): void;
421
422Obtains audio assets. This API uses an asynchronous callback to return the result.
423
424**System capability**: SystemCapability.FileManagement.UserFileManager.Core
425
426**Required permissions**: ohos.permission.READ_AUDIO
427
428**Parameters**
429
430| Name  | Type                    | Mandatory| Description                     |
431| -------- | ------------------------ | ---- | ------------------------- |
432| options  | [FetchOptions](#fetchoptions)        | Yes  | Options for fetching the audio assets.             |
433| callback |  AsyncCallback<[FetchResult](#fetchresult)<[FileAsset](#fileasset)>> | Yes  | Callback invoked to return the audio assets obtained.|
434
435**Example**
436
437```ts
438import dataSharePredicates from '@ohos.data.dataSharePredicates';
439
440async function example() {
441  console.info('getAudioAssets');
442  let predicates = new dataSharePredicates.DataSharePredicates();
443  let fetchOptions = {
444    fetchColumns: [],
445    predicates: predicates
446  };
447
448  mgr.getAudioAssets(fetchOptions, async (err, fetchResult) => {
449    if (fetchResult != undefined) {
450      console.info('fetchFileResult success');
451      let fileAsset = await fetchResult.getFirstObject();
452      if (fileAsset != undefined) {
453        console.info("fileAsset.displayName :" + fileAsset.displayName);
454      }
455    } else {
456      console.error('fetchFileResult fail' + err);
457    }
458  });
459}
460```
461
462### getAudioAssets
463
464getAudioAssets(options: FetchOptions): Promise<FetchResult<FileAsset>>;
465
466Obtains audio assets. This API uses a promise to return the result.
467
468**System capability**: SystemCapability.FileManagement.UserFileManager.Core
469
470**Required permissions**: ohos.permission.READ_AUDIO
471
472**Parameters**
473
474| Name  | Type                    | Mandatory| Description                     |
475| -------- | ------------------------ | ---- | ------------------------- |
476| options  | [FetchOptions](#fetchoptions)        | Yes  | Options for fetching the audio assets.             |
477
478**Return value**
479
480| Type                       | Description          |
481| --------------------------- | -------------- |
482| Promise<[FetchResult](#fetchresult)<[FileAsset](#fileasset)>> | Promise used to return the audio assets obtained.|
483
484**Example**
485
486```ts
487import dataSharePredicates from '@ohos.data.dataSharePredicates';
488
489async function example() {
490  console.info('getAudioAssets');
491  let predicates = new dataSharePredicates.DataSharePredicates();
492  let fetchOptions = {
493    fetchColumns: [],
494    predicates: predicates
495  };
496  try {
497    var fetchResult = await mgr.getAudioAssets(fetchOptions);
498  } catch (err) {
499    console.error('getAudioAssets failed, message = ', err);
500  }
501
502  if (fetchResult != undefined) {
503    console.info('fetchFileResult success');
504    let fileAsset = await fetchResult.getFirstObject();
505    if (fileAsset != undefined) {
506      console.info("fileAsset.displayName :" + fileAsset.displayName);
507    }
508  }
509}
510```
511
512### delete
513
514delete(uri: string, callback: AsyncCallback<void>): void;
515
516Deletes a media file. This API uses an asynchronous callback to return the result. The deleted file is moved to the recycle bin.
517
518**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.READ_AUDIO, and ohos.permission.WRITE_AUDIO
519
520**System capability**: SystemCapability.FileManagement.UserFileManager.Core
521
522**Parameters**
523
524| Name  | Type                     | Mandatory| Description      |
525| -------- | ------------------------- | ---- | ---------- |
526| uri | string | Yes  | URI of the media file to delete.|
527| callback | AsyncCallback<void> | Yes  | Callback that returns no value.|
528
529**Example**
530
531```ts
532import dataSharePredicates from '@ohos.data.dataSharePredicates';
533
534async function example() {
535  console.info('deleteAssetDemo');
536  let predicates = new dataSharePredicates.DataSharePredicates();
537  let fetchOptions = {
538    fetchColumns: [],
539    predicates: predicates
540  };
541  try {
542    const fetchResult = await mgr.getPhotoAssets(fetchOptions);
543    var asset = await fetchResult.getFirstObject();
544  } catch (err) {
545    console.info('fetch failed, message =', err);
546  }
547
548  if (asset == undefined) {
549    console.error('asset not exist');
550    return;
551  }
552  mgr.delete(asset.uri, (err) => {
553    if (err == undefined) {
554      console.info("delete successfully");
555    } else {
556      console.error("delete failed with error: " + err);
557    }
558  });
559}
560```
561
562### delete
563
564delete(uri: string): Promise<void>;
565
566Deletes a media file. This API uses a promise to return the result. The deleted file is moved to the recycle bin.
567
568**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.READ_AUDIO, and ohos.permission.WRITE_AUDIO
569
570**System capability**: SystemCapability.FileManagement.UserFileManager.Core
571
572**Parameters**
573
574| Name  | Type                     | Mandatory| Description      |
575| -------- | ------------------------- | ---- | ---------- |
576| uri | string | Yes  | URI of the media file to delete.|
577
578**Return value**
579
580| Type                                   | Description             |
581| --------------------------------------- | ----------------- |
582| Promise<void>| Promise that returns no value.|
583
584**Example**
585
586```ts
587import dataSharePredicates from '@ohos.data.dataSharePredicates';
588
589async function example() {
590  console.info('deleteDemo');
591  let predicates = new dataSharePredicates.DataSharePredicates();
592  let fetchOptions = {
593    fetchColumns: [],
594    predicates: predicates
595  };
596  try {
597    const fetchResult = await mgr.getPhotoAssets(fetchOptions);
598    var asset = await fetchResult.getFirstObject();
599  } catch (err) {
600    console.info('fetch failed, message =', err);
601  }
602
603  if (asset == undefined) {
604    console.error('asset not exist');
605    return;
606  }
607  try {
608    await mgr.delete(asset.uri);
609    console.info("delete successfully");
610  } catch (err) {
611    console.error("delete failed with error: " + err);
612  }
613}
614```
615
616### on
617
618on(type: ChangeEvent, callback: Callback<void>): void
619
620Subscribes to changes of the file management library. This API uses a callback to return the result.
621
622**System capability**: SystemCapability.FileManagement.UserFileManager.Core
623
624**Parameters**
625
626| Name  | Type                | Mandatory| Description                                                        |
627| -------- | -------------------- | ---- | ------------------------------------------------------------ |
628| 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.|
629| callback | Callback&lt;void&gt; | Yes  | Callback that returns no value.                                                  |
630
631**Example**
632
633```ts
634async function example() {
635  console.info('onDemo');
636  let count = 0;
637  mgr.on('imageChange', () => {
638    count++;
639    // Image file changed. Do something.
640  });
641  try {
642    let testFileName = "testFile" + Date.now() + ".jpg";
643    let fileAsset = await mgr.createPhotoAsset(testFileName);
644    console.info('createPhotoAsset file displayName' + fileAsset.displayName);
645    console.info('createPhotoAsset successfully');
646  } catch (err) {
647    console.error('createPhotoAsset failed, message = ' + err);
648  }
649  //sleep 1s
650  if (count > 0) {
651    console.info("onDemo success");
652  } else {
653    console.error("onDemo fail");
654  }
655  mgr.off('imageChange', () => {
656    // Unsubscription succeeds.
657  });
658}
659```
660
661### off
662
663off(type: ChangeEvent, callback?: Callback&lt;void&gt;): void
664
665Unsubscribes from changes of the file management library. This API uses a callback to return the result.
666
667**System capability**: SystemCapability.FileManagement.UserFileManager.Core
668
669**Parameters**
670
671| Name  | Type                | Mandatory| Description                                                        |
672| -------- | -------------------- | ---- | ------------------------------------------------------------ |
673| 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.|
674| callback | Callback&lt;void&gt; | No  | Callback that returns no value.                                                  |
675
676**Example**
677
678```ts
679async function example() {
680  console.info('offDemo');
681  let count = 0;
682  mgr.on('imageChange', () => {
683    count++;
684    // Image file changed. Do something.
685  });
686
687  mgr.off('imageChange', () => {
688    // Unsubscription succeeds.
689  });
690
691  try {
692    let testFileName = "testFile" + Date.now() + ".jpg";
693    let fileAsset = await mgr.createPhotoAsset(testFileName);
694    console.info('createPhotoAsset file displayName' + fileAsset.displayName);
695    console.info('createPhotoAsset successfully');
696  } catch (err) {
697    console.error('createPhotoAsset failed, message = ' + err);
698  }
699  //sleep 1s
700  if (count == 0) {
701    console.info("offDemo success");
702  } else {
703    console.error("offDemo fail");
704  }
705}
706```
707
708### getActivePeers
709
710getActivePeers(callback: AsyncCallback&lt;Array&lt;PeerInfo&gt;&gt;): void;
711
712Obtains information about online peer devices. This API uses an asynchronous callback to return the result.
713
714**System capability**: SystemCapability.FileManagement.UserFileManager.DistributedCore
715
716**Parameters**
717
718| Name  | Type                             | Mandatory| Description        |
719| -------- | --------------------------------- | ---- | ------------ |
720| callback | AsyncCallback&lt;Array&lt;[PeerInfo](#peerinfo)&gt;&gt; | Yes  | Callback invoked to return the online peer device list.|
721
722**Example**
723
724```ts
725async function example() {
726  console.info('getActivePeersDemo');
727  mgr.getActivePeers((err, devicesInfo) => {
728    if (devicesInfo != undefined) {
729      console.log('getActivePeers succeed.');
730      for (let i = 0; i < devicesInfo.length; i++) {
731        console.info('get distributed info ' + devicesInfo[i].deviceName + devicesInfo[i].networkId);
732      }
733    } else {
734      console.error('getActivePeers failed. message = ', err);
735    }
736  });
737}
738```
739
740### getActivePeers
741
742getActivePeers(): Promise&lt;Array&lt;PeerInfo&gt;&gt;;
743
744Obtains information about online peer devices. This API uses a promise to return the result.
745
746**System capability**: SystemCapability.FileManagement.UserFileManager.DistributedCore
747
748**Return value**
749
750| Type                       | Description                         |
751| --------------------------- | ----------------------------- |
752| Promise&lt;Array&lt;[PeerInfo](#peerinfo)&gt;&gt; | Promise used to return the online device list.|
753
754**Example**
755
756```ts
757async function example() {
758  console.info('getActivePeersDemo');
759  try {
760    var devicesInfo = await mgr.getActivePeers();
761  } catch (err) {
762    console.error('getActivePeers failed. message = ', err);
763  }
764  if (devicesInfo != undefined) {
765    console.log('getActivePeers succeed.');
766    for (let i = 0; i < devicesInfo.length; i++) {
767      console.info('get distributed info ' + devicesInfo[i].deviceName + devicesInfo[i].networkId);
768    }
769  } else {
770    console.error('get distributed fail');
771  }
772}
773```
774
775### getAllPeers
776
777getAllPeers(callback: AsyncCallback&lt;Array&lt;PeerInfo&gt;&gt;): void;
778
779Obtains information about all peer devices. This API uses an asynchronous callback to return the result.
780
781**System capability**: SystemCapability.FileManagement.UserFileManager.DistributedCore
782
783**Parameters**
784
785| Name  | Type                             | Mandatory| Description        |
786| -------- | --------------------------------- | ---- | ------------ |
787| callback | AsyncCallback&lt;Array&lt;[PeerInfo](#peerinfo)&gt;&gt; | Yes  | Callback invoked to return the online peer device list.|
788
789**Example**
790
791```ts
792async function example() {
793  console.info('getAllPeersDemo');
794  mgr.getAllPeers((err, devicesInfo) => {
795    if (devicesInfo != undefined) {
796      console.log('getAllPeers succeed.');
797      for (let i = 0; i < devicesInfo.length; i++) {
798        console.info('get distributed info ' + devicesInfo[i].deviceName + devicesInfo[i].networkId);
799      }
800    } else {
801      console.error('getAllPeers failed. message = ', err);
802    }
803  });
804}
805```
806
807### getAllPeers
808
809getAllPeers(): Promise&lt;Array&lt;PeerInfo&gt;&gt;;
810
811Obtains information about all peer devices. This API uses a promise to return the result.
812
813**System capability**: SystemCapability.FileManagement.UserFileManager.DistributedCore
814
815**Return value**
816
817| Type                       | Description                         |
818| --------------------------- | ----------------------------- |
819| Promise&lt;Array&lt;[PeerInfo](#peerinfo)&gt;&gt; | Promise used to return the peer device list.|
820
821**Example**
822
823```ts
824async function example() {
825  console.info('getAllPeersDemo');
826  try {
827    var devicesInfo = await mgr.getAllPeers();
828  } catch (err) {
829    console.error('getAllPeers failed. message = ', err);
830  }
831  if (devicesInfo != undefined) {
832    console.log('getAllPeers succeed.');
833    for (let i = 0; i < devicesInfo.length; i++) {
834      console.info('get distributed info ' + devicesInfo[i].deviceName + devicesInfo[i].networkId);
835    }
836  } else {
837    console.error('get distributed fail');
838  }
839}
840```
841
842### release
843
844release(callback: AsyncCallback&lt;void&gt;): void
845
846Releases this **UserFileManager** instance. This API uses an asynchronous callback to return the result.
847Call this API when the APIs in the **UserFileManager** instance are no longer used.
848
849**System capability**: SystemCapability.FileManagement.UserFileManager.Core
850
851**Parameters**
852
853| Name  | Type                     | Mandatory| Description                |
854| -------- | ------------------------- | ---- | -------------------- |
855| callback | AsyncCallback&lt;void&gt; | Yes  | Callback that returns no value.|
856
857**Example**
858
859```ts
860async function example() {
861  console.info('releaseDemo');
862  mgr.release((err) => {
863    if (err != undefined) {
864      console.error('release failed. message = ', err);
865    } else {
866      console.info('release ok.');
867    }
868  });
869}
870```
871
872### release
873
874release(): Promise&lt;void&gt;
875
876Releases this **UserFileManager** instance. This API uses a promise to return the result.
877Call this API when the APIs in the **UserFileManager** instance are no longer used.
878
879**System capability**: SystemCapability.FileManagement.UserFileManager.Core
880
881**Return value**
882
883| Type               | Description                             |
884| ------------------- | --------------------------------- |
885| Promise&lt;void&gt; | Promise that returns no value.|
886
887**Example**
888
889```ts
890async function example() {
891  console.info('releaseDemo');
892  try {
893    await mgr.release();
894    console.info('release ok.');
895  } catch (err) {
896    console.error('release failed. message = ', err);
897  }
898}
899```
900
901## FileAsset
902
903Provides APIs for encapsulating file asset attributes.
904
905### Attributes
906
907**System capability**: SystemCapability.FileManagement.UserFileManager.Core
908
909| Name                     | Type                    | Readable| Writable| Description                                                  |
910| ------------------------- | ------------------------ | ---- | ---- | ------------------------------------------------------ |
911| uri                       | string                   | Yes  | No  | File asset URI, for example, **dataability:///media/image/2**.        |
912| fileType   | [FileType](#filetype) | Yes  | No  | Type of the file.                                              |
913| displayName               | string                   | Yes  | Yes  | File name, including the file name extension, to display.                                |
914
915
916### get
917
918get(member: string): MemberType;
919
920Obtains the value of a **FileAsset** parameter.
921
922**System capability**: SystemCapability.FileManagement.UserFileManager.Core
923
924**Parameters**
925
926| Name     | Type                       | Mandatory  | Description   |
927| -------- | ------------------------- | ---- | ----- |
928| member | string | Yes   | Name of the parameter to obtain, for example, **ImageVideoKey.URI**.|
929
930**Example**
931
932```ts
933import dataSharePredicates from '@ohos.data.dataSharePredicates';
934
935async function example() {
936  console.info('fileAssetGetDemo');
937  try {
938    let predicates = new dataSharePredicates.DataSharePredicates();
939    let fetchOption = {
940      fetchColumns: [],
941      predicates: predicates
942    };
943    let fetchResult = await mgr.getPhotoAssets(fetchOption);
944    let fileAsset = await fetchResult.getFirstObject();
945    let title = userFileManager.ImageVideoKey.TITLE;
946    let fileAssetTitle = fileAsset.get(title.toString());
947    console.info('fileAsset Get fileAssetTitle = ', fileAssetTitle);
948  } catch (err) {
949    console.error('release failed. message = ', err);
950  }
951}
952```
953
954### set
955
956set(member: string, value: string): void;
957
958Sets a **FileAsset** parameter.
959
960**System capability**: SystemCapability.FileManagement.UserFileManager.Core
961
962**Parameters**
963
964| Name     | Type                       | Mandatory  | Description   |
965| -------- | ------------------------- | ---- | ----- |
966| member | string | Yes   | Name of the parameter to set, for example, **ImageVideoKey.URI**.|
967| value | string | Yes   | Value to set. Only the value of **ImageVideoKey.TITLE** can be changed.|
968
969**Example**
970
971```ts
972import dataSharePredicates from '@ohos.data.dataSharePredicates';
973
974async function example() {
975  console.info('fileAssetSetDemo');
976  try {
977    let predicates = new dataSharePredicates.DataSharePredicates();
978    let fetchOption = {
979      fetchColumns: [],
980      predicates: predicates
981    };
982    let fetchResult = await mgr.getPhotoAssets(fetchOption);
983    let fileAsset = await fetchResult.getFirstObject();
984    let title = userFileManager.ImageVideoKey.TITLE;
985    fileAsset.set(title.toString(), "newTitle");
986  } catch (err) {
987    console.error('release failed. message = ', err);
988  }
989}
990```
991
992### commitModify
993
994commitModify(callback: AsyncCallback&lt;void&gt;): void
995
996Commits the modification on the file metadata to the database. This API uses an asynchronous callback to return the result.
997
998**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.WRITE_AUDIO
999
1000**System capability**: SystemCapability.FileManagement.UserFileManager.Core
1001
1002**Parameters**
1003
1004| Name     | Type                       | Mandatory  | Description   |
1005| -------- | ------------------------- | ---- | ----- |
1006| callback | AsyncCallback&lt;void&gt; | Yes   | Callback that returns no value.|
1007
1008**Example**
1009
1010```ts
1011import dataSharePredicates from '@ohos.data.dataSharePredicates';
1012
1013async function example() {
1014  console.info('commitModifyDemo');
1015  let predicates = new dataSharePredicates.DataSharePredicates();
1016  let fetchOption = {
1017    fetchColumns: [],
1018    predicates: predicates
1019  };
1020  let fetchResult = await mgr.getPhotoAssets(fetchOption);
1021  let fileAsset = await fetchResult.getFirstObject();
1022  let title = userFileManager.ImageVideoKey.TITLE;
1023  let fileAssetTitle = fileAsset.get(title.toString());
1024  console.info('fileAsset Get fileAssetTitle = ', fileAssetTitle);
1025  fileAsset.set(title.toString(), "newTitle");
1026  fileAsset.commitModify((err) => {
1027    if (err == undefined) {
1028      let newFileAssetTitle = fileAsset.get(title.toString());
1029      console.info('fileAsset Get newFileAssetTitle = ', newFileAssetTitle);
1030    } else {
1031      console.error('commitModify failed, message =', err);
1032    }
1033  });
1034}
1035```
1036
1037### commitModify
1038
1039commitModify(): Promise&lt;void&gt;
1040
1041Commits the modification on the file metadata to the database. This API uses a promise to return the result.
1042
1043**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.WRITE_AUDIO
1044
1045**System capability**: SystemCapability.FileManagement.UserFileManager.Core
1046
1047**Return value**
1048
1049| Type                 | Description        |
1050| ------------------- | ---------- |
1051| Promise&lt;void&gt; | Promise that returns no value.|
1052
1053**Example**
1054
1055```ts
1056import dataSharePredicates from '@ohos.data.dataSharePredicates';
1057
1058async function example() {
1059  console.info('commitModifyDemo');
1060  let predicates = new dataSharePredicates.DataSharePredicates();
1061  let fetchOption = {
1062    fetchColumns: [],
1063    predicates: predicates
1064  };
1065  let fetchResult = await mgr.getPhotoAssets(fetchOption);
1066  let fileAsset = await fetchResult.getFirstObject();
1067  let title = userFileManager.ImageVideoKey.TITLE;
1068  let fileAssetTitle = fileAsset.get(title.toString());
1069  console.info('fileAsset Get fileAssetTitle = ', fileAssetTitle);
1070  fileAsset.set(title.toString(), "newTitle");
1071  try {
1072    await fileAsset.commitModify();
1073    let newFileAssetTitle = fileAsset.get(title.toString());
1074    console.info('fileAsset Get newFileAssetTitle = ', newFileAssetTitle);
1075  } catch (err) {
1076    console.error('release failed. message = ', err);
1077  }
1078}
1079```
1080
1081### open
1082
1083open(mode: string, callback: AsyncCallback&lt;number&gt;): void
1084
1085Opens this file asset. This API uses an asynchronous callback to return the result.
1086
1087**NOTE**<br>The write operations are mutually exclusive. After a write operation is complete, you must call **close** to release the resource.
1088
1089**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.READ_AUDIO, ohos.permission.WRITE_IMAGEVIDEO, or ohos.permission.WRITE_AUDIO
1090
1091**System capability**: SystemCapability.FileManagement.UserFileManager.Core
1092
1093**Parameters**
1094
1095| Name     | Type                         | Mandatory  | Description                                 |
1096| -------- | --------------------------- | ---- | ----------------------------------- |
1097| mode     | string                      | Yes   | File open mode, which can be **r** (read-only), **w** (write-only), or **rw** (read-write).|
1098| callback | AsyncCallback&lt;number&gt; | Yes   | Callback invoked to return the file descriptor.                           |
1099
1100**Example**
1101
1102```ts
1103async function example() {
1104  console.info('openDemo');
1105   let testFileName = "testFile" + Date.now() + ".jpg";
1106  const fileAsset = await mgr.createPhotoAsset(testFileName);
1107  fileAsset.open('rw', (err, fd) => {
1108    if (fd != undefined) {
1109      console.info('File fd' + fd);
1110      fileAsset.close(fd);
1111    } else {
1112      console.error('File err' + err);
1113    }
1114  });
1115}
1116```
1117
1118### open
1119
1120open(mode: string): Promise&lt;number&gt;
1121
1122Opens this file asset. This API uses a promise to return the result.
1123
1124**NOTE**<br>The write operations are mutually exclusive. After a write operation is complete, you must call **close** to release the resource.
1125
1126**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.READ_AUDIO, ohos.permission.WRITE_IMAGEVIDEO, or ohos.permission.WRITE_AUDIO
1127
1128**System capability**: SystemCapability.FileManagement.UserFileManager.Core
1129
1130**Parameters**
1131
1132| Name | Type    | Mandatory  | Description                                 |
1133| ---- | ------ | ---- | ----------------------------------- |
1134| mode | string | Yes   | File open mode, which can be **r** (read-only), **w** (write-only), or **rw** (read-write).|
1135
1136**Return value**
1137
1138| Type                   | Description           |
1139| --------------------- | ------------- |
1140| Promise&lt;number&gt; | Promise used to return the file descriptor.|
1141
1142**Example**
1143
1144```ts
1145async function example() {
1146  console.info('openDemo');
1147  try {
1148    let testFileName = "testFile" + Date.now() + ".jpg";
1149    const fileAsset = await mgr.createPhotoAsset(testFileName);
1150    let fd = await fileAsset.open('rw');
1151    if (fd != undefined) {
1152      console.info('File fd' + fd);
1153      fileAsset.close(fd);
1154    } else {
1155      console.error(' open File fail');
1156    }
1157  } catch (err) {
1158    console.error('open Demo err' + err);
1159  }
1160}
1161```
1162
1163### close
1164
1165close(fd: number, callback: AsyncCallback&lt;void&gt;): void
1166
1167Closes this file asset. This API uses an asynchronous callback to return the result.
1168
1169**System capability**: SystemCapability.FileManagement.UserFileManager.Core
1170
1171**Parameters**
1172
1173| Name     | Type                       | Mandatory  | Description   |
1174| -------- | ------------------------- | ---- | ----- |
1175| fd       | number                    | Yes   | File descriptor.|
1176| callback | AsyncCallback&lt;void&gt; | Yes   | Callback that returns no value.|
1177
1178**Example**
1179
1180```ts
1181import dataSharePredicates from '@ohos.data.dataSharePredicates';
1182
1183async function example() {
1184  console.info('closeDemo');
1185  try {
1186    let predicates = new dataSharePredicates.DataSharePredicates();
1187    let fetchOption = {
1188      fetchColumns: [],
1189      predicates: predicates
1190    };
1191    let fetchResult = await mgr.getPhotoAssets(fetchOption);
1192    const fileAsset = await fetchResult.getFirstObject();
1193    let fd = await fileAsset.open('rw');
1194    console.info('file fd', fd);
1195    fileAsset.close(fd, (err) => {
1196      if (err == undefined) {
1197        console.info('asset close succeed.');
1198      } else {
1199        console.error('close failed, message = ' + err);
1200      }
1201    });
1202  } catch (err) {
1203    console.error('close failed, message = ' + err);
1204  }
1205}
1206```
1207
1208### close
1209
1210close(fd: number): Promise&lt;void&gt;
1211
1212Closes this file asset. This API uses a promise to return the result.
1213
1214**System capability**: SystemCapability.FileManagement.UserFileManager.Core
1215
1216**Parameters**
1217
1218| Name | Type    | Mandatory  | Description   |
1219| ---- | ------ | ---- | ----- |
1220| fd   | number | Yes   | File descriptor.|
1221
1222**Return value**
1223
1224| Type                 | Description        |
1225| ------------------- | ---------- |
1226| Promise&lt;void&gt; | Promise that returns no value.|
1227
1228**Example**
1229
1230```ts
1231import dataSharePredicates from '@ohos.data.dataSharePredicates';
1232
1233async function example() {
1234  console.info('closeDemo');
1235  try {
1236    let predicates = new dataSharePredicates.DataSharePredicates();
1237    let fetchOption = {
1238      fetchColumns: [],
1239      predicates: predicates
1240    };
1241    let fetchResult = await mgr.getPhotoAssets(fetchOption);
1242    const asset = await fetchResult.getFirstObject();
1243    let fd = await asset.open('rw');
1244    console.info('file fd', fd);
1245    await asset.close(fd);
1246    console.info('asset close succeed.');
1247  } catch (err) {
1248    console.error('close failed, message = ' + err);
1249  }
1250}
1251```
1252
1253### getThumbnail
1254
1255getThumbnail(callback: AsyncCallback&lt;image.PixelMap&gt;): void
1256
1257Obtains the thumbnail of this file asset. This API uses an asynchronous callback to return the result.
1258
1259**Required permissions**: ohos.permission.READ_IMAGEVIDEO or ohos.permission.READ_AUDIO
1260
1261**System capability**: SystemCapability.FileManagement.UserFileManager.Core
1262
1263**Parameters**
1264
1265| Name     | Type                                 | Mandatory  | Description              |
1266| -------- | ----------------------------------- | ---- | ---------------- |
1267| callback | AsyncCallback&lt;[image.PixelMap](js-apis-image.md#pixelmap7)&gt; | Yes   | Callback invoked to return the pixel map of the thumbnail.|
1268
1269**Example**
1270
1271```ts
1272import dataSharePredicates from '@ohos.data.dataSharePredicates';
1273
1274async function example() {
1275  console.info('getThumbnailDemo');
1276  let predicates = new dataSharePredicates.DataSharePredicates();
1277  let fetchOption = {
1278    fetchColumns: [],
1279    predicates: predicates
1280  };
1281  let fetchResult = await mgr.getPhotoAssets(fetchOption);
1282  const asset = await fetchResult.getFirstObject();
1283  console.info('asset displayName = ', asset.displayName);
1284  asset.getThumbnail((err, pixelMap) => {
1285    if (err == undefined) {
1286      console.info('getThumbnail successful ' + pixelMap);
1287    } else {
1288      console.error('getThumbnail fail', err);
1289    }
1290  });
1291}
1292```
1293
1294### getThumbnail
1295
1296getThumbnail(size: image.Size, callback: AsyncCallback&lt;image.PixelMap&gt;): void
1297
1298Obtains the file thumbnail of the given size. This API uses an asynchronous callback to return the result.
1299
1300**Required permissions**: ohos.permission.READ_IMAGEVIDEO or ohos.permission.READ_AUDIO
1301
1302**System capability**: SystemCapability.FileManagement.UserFileManager.Core
1303
1304**Parameters**
1305
1306| Name     | Type                                 | Mandatory  | Description              |
1307| -------- | ----------------------------------- | ---- | ---------------- |
1308| size     | [image.Size](js-apis-image.md#size) | Yes   | Size of the thumbnail to obtain.           |
1309| callback | AsyncCallback&lt;[image.PixelMap](js-apis-image.md#pixelmap7)&gt; | Yes   | Callback invoked to return the pixel map of the thumbnail.|
1310
1311**Example**
1312
1313```ts
1314import dataSharePredicates from '@ohos.data.dataSharePredicates';
1315
1316async function example() {
1317  console.info('getThumbnailDemo');
1318  let predicates = new dataSharePredicates.DataSharePredicates();
1319  let fetchOption = {
1320    fetchColumns: [],
1321    predicates: predicates
1322  };
1323  let size = { width: 720, height: 720 };
1324  let fetchResult = await mgr.getPhotoAssets(fetchOption);
1325  const asset = await fetchResult.getFirstObject();
1326  console.info('asset displayName = ', asset.displayName);
1327  asset.getThumbnail(size, (err, pixelMap) => {
1328    if (err == undefined) {
1329      console.info('getThumbnail successful ' + pixelMap);
1330    } else {
1331      console.error('getThumbnail fail', err);
1332    }
1333  });
1334}
1335```
1336
1337### getThumbnail
1338
1339getThumbnail(size?: image.Size): Promise&lt;image.PixelMap&gt;
1340
1341Obtains the file thumbnail of the given size. This API uses a promise to return the result.
1342
1343**Required permissions**: ohos.permission.READ_IMAGEVIDEO or ohos.permission.READ_AUDIO
1344
1345**System capability**: SystemCapability.FileManagement.UserFileManager.Core
1346
1347**Parameters**
1348
1349| Name | Type            | Mandatory  | Description   |
1350| ---- | -------------- | ---- | ----- |
1351| size | [image.Size](js-apis-image.md#size) | No   | Size of the thumbnail to obtain.|
1352
1353**Return value**
1354
1355| Type                           | Description                   |
1356| ----------------------------- | --------------------- |
1357| Promise&lt;[image.PixelMap](js-apis-image.md#pixelmap7)&gt; | Promise used to return the pixel map of the thumbnail.|
1358
1359**Example**
1360
1361```ts
1362import dataSharePredicates from '@ohos.data.dataSharePredicates';
1363
1364async function example() {
1365  console.info('getThumbnailDemo');
1366  let predicates = new dataSharePredicates.DataSharePredicates();
1367  let fetchOption = {
1368    fetchColumns: [],
1369    predicates: predicates
1370  };
1371  let size = { width: 720, height: 720 };
1372  let fetchResult = await mgr.getPhotoAssets(fetchOption);
1373  const asset = await fetchResult.getFirstObject();
1374  console.info('asset displayName = ', asset.displayName);
1375  asset.getThumbnail(size).then((pixelMap) => {
1376    console.info('getThumbnail successful ' + pixelMap);
1377  }).catch((err) => {
1378    console.error('getThumbnail fail' + err);
1379  });
1380}
1381```
1382
1383### favorite
1384
1385favorite(isFavorite: boolean, callback: AsyncCallback&lt;void&gt;): void
1386
1387Favorites or unfavorites this file asset. This API uses an asynchronous callback to return the result.
1388
1389**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.WRITE_AUDIO
1390
1391**System capability**: SystemCapability.FileManagement.UserFileManager.Core
1392
1393**Parameters**
1394
1395| Name       | Type                       | Mandatory  | Description                                |
1396| ---------- | ------------------------- | ---- | ---------------------------------- |
1397| isFavorite | boolean                   | Yes   | Operation to perform. The value **true** means to favorite the file asset, and **false** means the opposite.|
1398| callback   | AsyncCallback&lt;void&gt; | Yes   | Callback that returns no value.                             |
1399
1400**Example**
1401
1402```ts
1403import dataSharePredicates from '@ohos.data.dataSharePredicates';
1404
1405async function example() {
1406  console.info('favoriteDemo');
1407  let predicates = new dataSharePredicates.DataSharePredicates();
1408  let fetchOption = {
1409    fetchColumns: [],
1410    predicates: predicates
1411  };
1412  let fetchResult = await mgr.getPhotoAssets(fetchOption);
1413  const asset = await fetchResult.getFirstObject();
1414  asset.favorite(true, (err) => {
1415    if (err == undefined) {
1416      console.info("favorite successfully");
1417    } else {
1418      console.error("favorite failed with error:" + err);
1419    }
1420  });
1421}
1422```
1423
1424### favorite
1425
1426favorite(isFavorite: boolean): Promise&lt;void&gt;
1427
1428Favorites or unfavorites this file asset. This API uses a promise to return the result.
1429
1430**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.WRITE_AUDIO
1431
1432**System capability**: SystemCapability.FileManagement.UserFileManager.Core
1433
1434**Parameters**
1435
1436| Name       | Type     | Mandatory  | Description                                |
1437| ---------- | ------- | ---- | ---------------------------------- |
1438| isFavorite | boolean | Yes   | Operation to perform. The value **true** means to favorite the file asset, and **false** means the opposite.|
1439
1440**Return value**
1441
1442| Type                 | Description        |
1443| ------------------- | ---------- |
1444| Promise&lt;void&gt; | Promise that returns no value.|
1445
1446**Example**
1447
1448```ts
1449import dataSharePredicates from '@ohos.data.dataSharePredicates';
1450
1451async function example() {
1452  console.info('favoriteDemo');
1453  let predicates = new dataSharePredicates.DataSharePredicates();
1454  let fetchOption = {
1455    fetchColumns: [],
1456    predicates: predicates
1457  };
1458  let fetchResult = await mgr.getPhotoAssets(fetchOption);
1459  const asset = await fetchResult.getFirstObject();
1460  asset.favorite(true).then(function () {
1461    console.info("favorite successfully");
1462  }).catch(function (err) {
1463    console.error("favorite failed with error:" + err);
1464  });
1465}
1466```
1467
1468## FetchResult
1469
1470Provides APIs to manage the file retrieval result.
1471
1472### getCount
1473
1474getCount(): number
1475
1476Obtains the total number of files in the result set.
1477
1478**System capability**: SystemCapability.FileManagement.UserFileManager.Core
1479
1480**Return value**
1481
1482| Type    | Description      |
1483| ------ | -------- |
1484| number | Total number of files.|
1485
1486**Example**
1487
1488```ts
1489import dataSharePredicates from '@ohos.data.dataSharePredicates';
1490
1491async function example() {
1492  console.info('getCountDemo');
1493  let predicates = new dataSharePredicates.DataSharePredicates();
1494  let fetchOption = {
1495    fetchColumns: [],
1496    predicates: predicates
1497  };
1498  let fetchResult = await mgr.getPhotoAssets(fetchOption);
1499  const fetchCount = fetchResult.getCount();
1500  console.info('fetchCount = ', fetchCount);
1501}
1502```
1503
1504### isAfterLast
1505
1506isAfterLast(): boolean
1507
1508Checks whether the cursor is in the last row of the result set.
1509
1510**System capability**: SystemCapability.FileManagement.UserFileManager.Core
1511
1512**Return value**
1513
1514| Type     | Description                                |
1515| ------- | ---------------------------------- |
1516| boolean | Returns **true** if the cursor is in the last row of the result set; returns **false** otherwise.|
1517
1518**Example**
1519
1520```ts
1521import dataSharePredicates from '@ohos.data.dataSharePredicates';
1522
1523async function example() {
1524  let predicates = new dataSharePredicates.DataSharePredicates();
1525  let fetchOption = {
1526    fetchColumns: [],
1527    predicates: predicates
1528  };
1529  let fetchResult = await mgr.getPhotoAssets(fetchOption);
1530  const fetchCount = fetchResult.getCount();
1531  console.info('count:' + fetchCount);
1532  let fileAsset = await fetchResult.getLastObject();
1533  if (!fetchResult.isAfterLast()) {
1534    console.info('fileAsset isAfterLast displayName = ', fileAsset.displayName);
1535  } else {
1536    console.info('fileAsset  not isAfterLast ');
1537  }
1538}
1539```
1540
1541### close
1542
1543close(): void
1544
1545Releases and invalidates this **FetchFileResult** instance. After this instance is released, the APIs in this instance cannot be invoked.
1546
1547**System capability**: SystemCapability.FileManagement.UserFileManager.Core
1548
1549**Example**
1550
1551```ts
1552import dataSharePredicates from '@ohos.data.dataSharePredicates';
1553
1554async function example() {
1555  console.info('fetchResultCloseDemo');
1556  let predicates = new dataSharePredicates.DataSharePredicates();
1557  let fetchOption = {
1558    fetchColumns: [],
1559    predicates: predicates
1560  };
1561  try {
1562    let fetchResult = await mgr.getPhotoAssets(fetchOption);
1563    await fetchResult.close();
1564    console.info('close succeed.');
1565  } catch (err) {
1566    console.error('close fail. message = ' + err);
1567  }
1568}
1569```
1570
1571### getFirstObject
1572
1573getFirstObject(callback: AsyncCallback&lt;T&gt;): void
1574
1575Obtains the first file asset in the result set. This API uses an asynchronous callback to return the result.
1576
1577**System capability**: SystemCapability.FileManagement.UserFileManager.Core
1578
1579**Parameters**
1580
1581| Name  | Type                                         | Mandatory| Description                                       |
1582| -------- | --------------------------------------------- | ---- | ------------------------------------------- |
1583| callback | AsyncCallback&lt;T&gt; | Yes  | Callback invoked to return the first file asset.|
1584
1585**Example**
1586
1587```ts
1588import dataSharePredicates from '@ohos.data.dataSharePredicates';
1589
1590async function example() {
1591  console.info('getFirstObjectDemo');
1592  let predicates = new dataSharePredicates.DataSharePredicates();
1593  let fetchOption = {
1594    fetchColumns: [],
1595    predicates: predicates
1596  };
1597  let fetchResult = await mgr.getPhotoAssets(fetchOption);
1598  fetchResult.getFirstObject((err, fileAsset) => {
1599    if (fileAsset != undefined) {
1600      console.info('fileAsset displayName: ', fileAsset.displayName);
1601    } else {
1602      console.error("fileAsset failed with err:" + err);
1603    }
1604  });
1605}
1606```
1607
1608### getFirstObject
1609
1610getFirstObject(): Promise&lt;T&gt;
1611
1612Obtains the first file asset in the result set. This API uses a promise to return the result.
1613
1614**System capability**: SystemCapability.FileManagement.UserFileManager.Core
1615
1616**Return value**
1617
1618| Type                                   | Description                      |
1619| --------------------------------------- | -------------------------- |
1620| Promise&lt;T&gt; | Promise used to return the first file asset.|
1621
1622**Example**
1623
1624```ts
1625import dataSharePredicates from '@ohos.data.dataSharePredicates';
1626
1627async function example() {
1628  console.info('getFirstObjectDemo');
1629  let predicates = new dataSharePredicates.DataSharePredicates();
1630  let fetchOption = {
1631    fetchColumns: [],
1632    predicates: predicates
1633  };
1634  let fetchResult = await mgr.getPhotoAssets(fetchOption);
1635  let fileAsset = await fetchResult.getFirstObject();
1636  console.info('fileAsset displayName: ', fileAsset.displayName);
1637}
1638```
1639
1640### getNextObject
1641
1642 getNextObject(callback: AsyncCallback&lt;T&gt;): void
1643
1644Obtains the next file asset in the result set. This API uses an asynchronous callback to return the result.
1645
1646**System capability**: SystemCapability.FileManagement.UserFileManager.Core
1647
1648**Parameters**
1649
1650| Name   | Type                                         | Mandatory| Description                                     |
1651| --------- | --------------------------------------------- | ---- | ----------------------------------------- |
1652| callbacke | AsyncCallback&lt;T&gt; | Yes  | Callback invoked to return the next file asset.|
1653
1654**Example**
1655
1656```ts
1657import dataSharePredicates from '@ohos.data.dataSharePredicates';
1658
1659async function example() {
1660  console.info('getNextObjectDemo');
1661  let predicates = new dataSharePredicates.DataSharePredicates();
1662  let fetchOption = {
1663    fetchColumns: [],
1664    predicates: predicates
1665  };
1666  let fetchResult = await mgr.getPhotoAssets(fetchOption);
1667  await fetchResult.getFirstObject();
1668  if (fetchResult.isAfterLast()) {
1669    fetchResult.getNextObject((err, fileAsset) => {
1670      if (fileAsset != undefined) {
1671        console.info('fileAsset displayName: ', fileAsset.displayName);
1672      } else {
1673        console.error("fileAsset failed with err: " + err);
1674      }
1675    });
1676  }
1677}
1678```
1679
1680### getNextObject
1681
1682 getNextObject(): Promise&lt;T&gt;
1683
1684Obtains the next file asset in the result set. This API uses a promise to return the result.
1685
1686**System capability**: SystemCapability.FileManagement.UserFileManager.Core
1687
1688**Return value**
1689
1690| Type                                   | Description             |
1691| --------------------------------------- | ----------------- |
1692| Promise&lt;T&gt; | Promise used to return the next file asset obtained.|
1693
1694**Example**
1695
1696```ts
1697import dataSharePredicates from '@ohos.data.dataSharePredicates';
1698
1699async function example() {
1700  console.info('getNextObjectDemo');
1701  let predicates = new dataSharePredicates.DataSharePredicates();
1702  let fetchOption = {
1703    fetchColumns: [],
1704    predicates: predicates
1705  };
1706  let fetchResult = await mgr.getPhotoAssets(fetchOption);
1707  await fetchResult.getFirstObject();
1708  if (fetchResult.isAfterLast()) {
1709    let fileAsset = await fetchResult.getNextObject();
1710    console.info('fileAsset displayName: ', fileAsset.displayName);
1711  }
1712}
1713```
1714
1715### getLastObject
1716
1717getLastObject(callback: AsyncCallback&lt;T&gt;): void
1718
1719Obtains the last file asset in the result set. This API uses an asynchronous callback to return the result.
1720
1721**System capability**: SystemCapability.FileManagement.UserFileManager.Core
1722
1723**Parameters**
1724
1725| Name  | Type                                         | Mandatory| Description                       |
1726| -------- | --------------------------------------------- | ---- | --------------------------- |
1727| callback | AsyncCallback&lt;T&gt; | Yes  | Callback invoked to return the last file asset obtained.|
1728
1729**Example**
1730
1731```ts
1732import dataSharePredicates from '@ohos.data.dataSharePredicates';
1733
1734async function example() {
1735  console.info('getLastObjectDemo');
1736  let predicates = new dataSharePredicates.DataSharePredicates();
1737  let fetchOption = {
1738    fetchColumns: [],
1739    predicates: predicates
1740  };
1741  let fetchResult = await mgr.getPhotoAssets(fetchOption);
1742  fetchResult.getLastObject((err, fileAsset) => {
1743    if (fileAsset != undefined) {
1744      console.info('fileAsset displayName: ', fileAsset.displayName);
1745    } else {
1746      console.error("fileAsset failed with err: " + err);
1747    }
1748  });
1749}
1750```
1751
1752### getLastObject
1753
1754getLastObject(): Promise&lt;T&gt;
1755
1756Obtains the last file asset in the result set. This API uses a promise to return the result.
1757
1758**System capability**: SystemCapability.FileManagement.UserFileManager.Core
1759
1760**Return value**
1761
1762| Type                                   | Description             |
1763| --------------------------------------- | ----------------- |
1764| Promise&lt;T&gt; | Promise used to return the last file asset obtained.|
1765
1766**Example**
1767
1768```ts
1769import dataSharePredicates from '@ohos.data.dataSharePredicates';
1770
1771async function example() {
1772  console.info('getLastObjectDemo');
1773  let predicates = new dataSharePredicates.DataSharePredicates();
1774  let fetchOption = {
1775    fetchColumns: [],
1776    predicates: predicates
1777  };
1778  let fetchResult = await mgr.getPhotoAssets(fetchOption);
1779  let fileAsset = await fetchResult.getLastObject();
1780  console.info('fileAsset displayName: ', fileAsset.displayName);
1781}
1782```
1783
1784### getPositionObject
1785
1786getPositionObject(index: number, callback: AsyncCallback&lt;T&gt;): void
1787
1788Obtains a file asset with the specified index in the result set. This API uses an asynchronous callback to return the result.
1789
1790**System capability**: SystemCapability.FileManagement.UserFileManager.Core
1791
1792**Parameters**
1793
1794| Name      | Type                                      | Mandatory  | Description                |
1795| -------- | ---------------------------------------- | ---- | ------------------ |
1796| index    | number                                   | Yes   | Index of the file asset to obtain. The value starts from **0**.    |
1797| callback | AsyncCallback&lt;T&gt; | Yes   | Callback invoked to return the file asset obtained.|
1798
1799**Example**
1800
1801```ts
1802import dataSharePredicates from '@ohos.data.dataSharePredicates';
1803
1804async function example() {
1805  console.info('getPositionObjectDemo');
1806  let predicates = new dataSharePredicates.DataSharePredicates();
1807  let fetchOption = {
1808    fetchColumns: [],
1809    predicates: predicates
1810  };
1811  let fetchResult = await mgr.getPhotoAssets(fetchOption);
1812  fetchResult.getPositionObject(0, (err, fileAsset) => {
1813    if (fileAsset != undefined) {
1814      console.info('fileAsset displayName: ', fileAsset.displayName);
1815    } else {
1816      console.error("fileAsset failed with err: " + err);
1817    }
1818  });
1819}
1820```
1821
1822### getPositionObject
1823
1824getPositionObject(index: number): Promise&lt;T&gt;
1825
1826Obtains a file asset with the specified index in the result set. This API uses a promise to return the result.
1827
1828**System capability**: SystemCapability.FileManagement.UserFileManager.Core
1829
1830**Parameters**
1831
1832| Name   | Type    | Mandatory  | Description            |
1833| ----- | ------ | ---- | -------------- |
1834| index | number | Yes   | Index of the file asset to obtain. The value starts from **0**.|
1835
1836**Return value**
1837
1838| Type                                   | Description             |
1839| --------------------------------------- | ----------------- |
1840| Promise&lt;T&gt; | Promise used to return the file asset obtained.|
1841
1842**Example**
1843
1844```ts
1845import dataSharePredicates from '@ohos.data.dataSharePredicates';
1846
1847async function example() {
1848  console.info('getPositionObjectDemo');
1849  let predicates = new dataSharePredicates.DataSharePredicates();
1850  let fetchOption = {
1851    fetchColumns: [],
1852    predicates: predicates
1853  };
1854  let fetchResult = await mgr.getPhotoAssets(fetchOption);
1855  let fileAsset = await fetchResult.getPositionObject(0);
1856  console.info('fileAsset displayName: ', fileAsset.displayName);
1857}
1858```
1859
1860## Album
1861
1862Provides APIs to manage albums.
1863
1864### Attributes
1865
1866**System capability**: SystemCapability.FileManagement.UserFileManager.Core
1867
1868| Name          | Type   | Readable  | Writable  | Description     |
1869| ------------ | ------ | ---- | ---- | ------- |
1870| albumName | string | Yes   | Yes   | Album name.   |
1871| albumUri | string | Yes   | No   | Album URI.  |
1872| dateModified | number | Yes   | No   | Date when the album was last modified.   |
1873| count | number | Yes   | No   | Number of files in the album.|
1874| coverUri | string | Yes   | No   | URI of the cover file of the album.
1875
1876### getPhotoAssets
1877
1878getPhotoAssets(options: FetchOptions, callback: AsyncCallback&lt;FetchResult&lt;FileAsset&gt;&gt;): void;
1879
1880Obtains image and video assets. This API uses an asynchronous callback to return the result.
1881
1882**Required permissions**: ohos.permission.READ_IMAGEVIDEO
1883
1884**System capability**: SystemCapability.FileManagement.UserFileManager.Core
1885
1886**Parameters**
1887
1888| Name  | Type                     | Mandatory| Description      |
1889| -------- | ------------------------- | ---- | ---------- |
1890| options | [FetchOptions](#fetchoptions) | Yes  | Options for fetching the image and video assets.|
1891| callback | AsyncCallback&lt;[FetchResult](#fetchresult)&lt;[FileAsset](#fileasset)&gt;&gt; | Yes  | Callback invoked to return the image and video assets obtained.|
1892
1893**Example**
1894
1895```ts
1896import dataSharePredicates from '@ohos.data.dataSharePredicates';
1897
1898async function example() {
1899  console.info('albumGetFileAssetsDemoCallback');
1900
1901  let predicates = new dataSharePredicates.DataSharePredicates();
1902  let albumFetchOptions = {
1903    predicates: predicates
1904  };
1905  let fetchOption = {
1906    fetchColumns: [],
1907    predicates: predicates
1908  };
1909  const albumList = await mgr.getPhotoAlbums(albumFetchOptions);
1910  const album = await albumList.getFirstObject();
1911  album.getPhotoAssets(fetchOption, (err, albumFetchResult) => {
1912    if (albumFetchResult != undefined) {
1913      console.info("album getPhotoAssets successfully, getCount: " + albumFetchResult.getCount());
1914    } else {
1915      console.error("album getPhotoAssets failed with error: " + err);
1916    }
1917  });
1918}
1919```
1920
1921### getPhotoAssets
1922
1923getPhotoAssets(options: FetchOptions): Promise&lt;FetchResult&lt;FileAsset&gt;&gt;;
1924
1925Obtains image and video assets. This API uses a promise to return the result.
1926
1927**Required permissions**: ohos.permission.READ_IMAGEVIDEO
1928
1929**System capability**: SystemCapability.FileManagement.UserFileManager.Core
1930
1931**Parameters**
1932
1933| Name  | Type                     | Mandatory| Description      |
1934| -------- | ------------------------- | ---- | ---------- |
1935| options | [FetchOptions](#fetchoptions) | Yes  | Options for fetching the image and video assets.|
1936| Promise | [FetchResult](#fetchresult)&lt;[FileAsset](#fileasset)&gt; | Yes  | Promise used to return the image and video assets obtained.|
1937
1938**Example**
1939
1940```ts
1941import dataSharePredicates from '@ohos.data.dataSharePredicates';
1942
1943async function example() {
1944  console.info('albumGetFileAssetsDemoPromise');
1945
1946  let predicates = new dataSharePredicates.DataSharePredicates();
1947  let albumFetchOptions = {
1948    predicates: predicates
1949  };
1950  let fetchOption = {
1951    fetchColumns: [],
1952    predicates: predicates
1953  };
1954  const albumList = await mgr.getPhotoAlbums(albumFetchOptions);
1955  const album = await albumList.getFirstObject();
1956  album.getPhotoAssets(fetchOption).then((albumFetchResult) => {
1957    console.info("album getFileAssets successfully, getCount: " + albumFetchResult.getCount());
1958  }).catch((err) => {
1959    console.error("album getFileAssets failed with error: " + err);
1960  });
1961}
1962```
1963
1964### commitModify
1965
1966commitModify(callback: AsyncCallback&lt;void&gt;): void;
1967
1968Commits the modification on the album attributes to the database. This API uses an asynchronous callback to return the result.
1969
1970**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
1971
1972**System capability**: SystemCapability.FileManagement.UserFileManager.Core
1973
1974**Parameters**
1975
1976| Name  | Type                     | Mandatory| Description      |
1977| -------- | ------------------------- | ---- | ---------- |
1978| callback | AsyncCallback&lt;void&gt; | Yes  | Callback that returns no value.|
1979
1980**Example**
1981
1982```ts
1983import dataSharePredicates from '@ohos.data.dataSharePredicates';
1984
1985async function example() {
1986  console.info('albumCommitModifyDemo');
1987  let predicates = new dataSharePredicates.DataSharePredicates();
1988  let albumFetchOptions = {
1989    predicates: predicates
1990  };
1991  const albumList = await mgr.getPhotoAlbums(albumFetchOptions);
1992  const album = await albumList.getFirstObject();
1993  album.albumName = 'hello';
1994  album.commitModify((err) => {
1995    if (err != undefined) {
1996      console.error("commitModify failed with error: " + err);
1997    } else {
1998      console.info("commitModify successfully");
1999    }
2000  });
2001}
2002```
2003
2004### commitModify
2005
2006commitModify(): Promise&lt;void&gt;;
2007
2008Commits the modification on the album attributes to the database. This API uses a promise to return the result.
2009
2010**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
2011
2012**System capability**: SystemCapability.FileManagement.UserFileManager.Core
2013
2014**Return value**
2015
2016| Type                 | Description          |
2017| ------------------- | ------------ |
2018| Promise&lt;void&gt; | Promise that returns no value.|
2019
2020**Example**
2021
2022```ts
2023import dataSharePredicates from '@ohos.data.dataSharePredicates';
2024
2025async function example() {
2026  console.info('albumCommitModifyDemo');
2027  let predicates = new dataSharePredicates.DataSharePredicates();
2028  let albumFetchOptions = {
2029    predicates: predicates
2030  };
2031  try {
2032    var albumList = await mgr.getPhotoAlbums(albumFetchOptions);
2033  } catch (err) {
2034    console.error('getPhotoAlbums failed. message = ', err);
2035  }
2036  const album = await albumList.getFirstObject();
2037  album.albumName = 'hello';
2038  album.commitModify().then(() => {
2039    console.info("commitModify successfully");
2040  }).catch((err) => {
2041    console.error("commitModify failed with error: " + err);
2042  });
2043}
2044```
2045
2046## PrivateAlbum
2047
2048Provides APIs for managing the system albums.
2049
2050### Attributes
2051
2052**System capability**: SystemCapability.FileManagement.UserFileManager.Core
2053
2054| Name          | Type   | Readable  | Writable  | Description     |
2055| ------------ | ------ | ---- | ---- | ------- |
2056| albumName | string | Yes   | Yes   | Album name.   |
2057| albumUri | string | Yes   | No   | Album URI.  |
2058| dateModified | number | Yes   | No   | Date when the album was last modified.   |
2059| count | number | Yes   | No   | Number of files in the album.|
2060| coverUri | string | Yes   | No   | URI of the cover file of the album.
2061
2062### getPhotoAssets
2063
2064getPhotoAssets(options: FetchOptions, callback: AsyncCallback&lt;FetchResult&lt;FileAsset&gt;&gt;): void;
2065
2066Obtains image and video assets from a system album. This API uses an asynchronous callback to return the result.
2067
2068**Required permissions**: ohos.permission.READ_IMAGEVIDEO
2069
2070**System capability**: SystemCapability.FileManagement.UserFileManager.Core
2071
2072**Parameters**
2073
2074| Name  | Type                     | Mandatory| Description      |
2075| -------- | ------------------------- | ---- | ---------- |
2076| options | [FetchOptions](#fetchoptions) | Yes  | Options for fetching the image and video assets.|
2077| callback | AsyncCallback&lt;[FetchResult](#fetchresult)&lt;[FileAsset](#fileasset)&gt;&gt; | Yes  | Callback invoked to return the image and video assets obtained.|
2078
2079**Example**
2080
2081```ts
2082import dataSharePredicates from '@ohos.data.dataSharePredicates';
2083
2084async function example() {
2085  console.info('privateAlbumGetFileAssetsDemoCallback');
2086  let albumList = await mgr.getPrivateAlbum(userFileManager.PrivateAlbumType.TYPE_TRASH);
2087  let predicates = new dataSharePredicates.DataSharePredicates();
2088  let fetchOption = {
2089    fetchColumns: [],
2090    predicates: predicates
2091  };
2092  const trashAlbum = await albumList.getFirstObject();
2093  trashAlbum.getPhotoAssets(fetchOption, (err, fetchResult) => {
2094    if (fetchResult != undefined) {
2095      let count = fetchResult.getCount();
2096      console.info('fetchResult.count = ', count);
2097    } else {
2098      console.error('getFileAssets failed, message = ', err);
2099    }
2100  });
2101}
2102
2103```
2104
2105### getPhotoAssets
2106
2107getPhotoAssets(options: FetchOptions): Promise&lt;FetchResult&lt;FileAsset&gt;&gt;;
2108
2109Obtains image and video assets from a system album. This API uses a promise to return the result.
2110
2111**Required permissions**: ohos.permission.READ_IMAGEVIDEO
2112
2113**System capability**: SystemCapability.FileManagement.UserFileManager.Core
2114
2115**Parameters**
2116
2117| Name  | Type                     | Mandatory| Description      |
2118| -------- | ------------------------- | ---- | ---------- |
2119| options | [FetchOptions](#fetchoptions) | Yes  | Options for fetching the image and video assets.|
2120
2121**Return value**
2122
2123| Type                                   | Description             |
2124| --------------------------------------- | ----------------- |
2125| Promise:[FetchResult](#fetchresult)&lt;[FileAsset](#fileasset)&gt;| Promise used to return the image and video assets obtained.|
2126
2127**Example**
2128
2129```ts
2130import dataSharePredicates from '@ohos.data.dataSharePredicates';
2131
2132async function example() {
2133  console.info('privateAlbumGetFileAssetsDemoPromise');
2134  let albumList = await mgr.getPrivateAlbum(userFileManager.PrivateAlbumType.TYPE_TRASH);
2135  let predicates = new dataSharePredicates.DataSharePredicates();
2136  let fetchOption = {
2137    fetchColumns: [],
2138    predicates: predicates
2139  };
2140  const trashAlbum = await albumList.getFirstObject();
2141  let fetchResult = await trashAlbum.getPhotoAssets(fetchOption);
2142  let count = fetchResult.getCount();
2143  console.info('fetchResult.count = ', count);
2144}
2145```
2146
2147### delete
2148
2149delete(uri: string, callback: AsyncCallback&lt;void&gt;): void;
2150
2151Deletes files from a system album.
2152
2153**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.READ_AUDIO, and ohos.permission.WRITE_AUDIO
2154
2155**System capability**: SystemCapability.FileManagement.UserFileManager.Core
2156
2157**Parameters**
2158
2159| Name  | Type                     | Mandatory| Description      |
2160| -------- | ------------------------- | ---- | ---------- |
2161| uri | string | Yes  | Album URI.|
2162| callback | AsyncCallback&lt;void&gt; | Yes  | Callback that returns no value.|
2163
2164**Example**
2165
2166```ts
2167import dataSharePredicates from '@ohos.data.dataSharePredicates';
2168
2169async function example() {
2170  console.info('privateAlbumDeleteCallback');
2171  let albumList = await mgr.getPrivateAlbum(userFileManager.PrivateAlbumType.TYPE_TRASH);
2172  let predicates = new dataSharePredicates.DataSharePredicates();
2173  let fetchOption = {
2174    fetchColumns: [],
2175    predicates: predicates
2176  };
2177  const trashAlbum = await albumList.getFirstObject();
2178  let fetchResult = await trashAlbum.getPhotoAssets(fetchOption);
2179  const fileAsset = await fetchResult.getFirstObject();
2180  let deleteFileUri = fileAsset.uri;
2181  trashAlbum.delete(deleteFileUri, (err) => {
2182    if (err != undefined) {
2183      console.error('trashAlbum.delete failed, message = ', err);
2184    } else {
2185      console.info('trashAlbum.delete successfully');
2186    }
2187  });
2188}
2189```
2190
2191### delete
2192
2193delete(uri: string): Promise&lt;void&gt;;
2194
2195Deletes files from a system album.
2196
2197**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.READ_AUDIO, and ohos.permission.WRITE_AUDIO
2198
2199**System capability**: SystemCapability.FileManagement.UserFileManager.Core
2200
2201**Parameters**
2202
2203| Name  | Type                     | Mandatory| Description      |
2204| -------- | ------------------------- | ---- | ---------- |
2205| uri | string | Yes  | Album URI.|
2206
2207**Return value**
2208
2209| Type                                   | Description             |
2210| --------------------------------------- | ----------------- |
2211| Promise&lt;void&gt;| Promise that returns no value.|
2212
2213**Example**
2214
2215```ts
2216import dataSharePredicates from '@ohos.data.dataSharePredicates';
2217
2218async function example() {
2219  console.info('privateAlbumDeleteDemoPromise');
2220  let albumList = await mgr.getPrivateAlbum(userFileManager.PrivateAlbumType.TYPE_TRASH);
2221  let predicates = new dataSharePredicates.DataSharePredicates();
2222  let fetchOption = {
2223    fetchColumns: [],
2224    predicates: predicates
2225  };
2226  const trashAlbum = await albumList.getFirstObject();
2227  let fetchResult = await trashAlbum.getPhotoAssets(fetchOption);
2228  const fileAsset = await fetchResult.getFirstObject();
2229  let deleteFileUri = fileAsset.uri;
2230  trashAlbum.delete(deleteFileUri).then(() => {
2231    console.info('trashAlbum.delete successfully');
2232  }).catch((err) => {
2233    console.error('trashAlbum.delete failed, message = ', err);
2234  });
2235}
2236```
2237
2238### recover
2239
2240recover(uri: string, callback: AsyncCallback&lt;void&gt;): void;
2241
2242Recovers files in a system album.
2243
2244**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.READ_AUDIO, and ohos.permission.WRITE_AUDIO
2245
2246**System capability**: SystemCapability.FileManagement.UserFileManager.Core
2247
2248**Parameters**
2249
2250| Name  | Type                     | Mandatory| Description      |
2251| -------- | ------------------------- | ---- | ---------- |
2252| uri | string | Yes  | Album URI.|
2253| callback | AsyncCallback&lt;void&gt; | Yes  | Callback that returns no value.|
2254
2255**Example**
2256
2257```ts
2258import dataSharePredicates from '@ohos.data.dataSharePredicates';
2259
2260async function example() {
2261  console.info('privateAlbumRecoverDemoCallback');
2262  let albumList = await mgr.getPrivateAlbum(userFileManager.PrivateAlbumType.TYPE_TRASH);
2263  let predicates = new dataSharePredicates.DataSharePredicates();
2264  let fetchOption = {
2265    fetchColumns: [],
2266    predicates: predicates
2267  };
2268  const trashAlbum = await albumList.getFirstObject();
2269  let fetchResult = await trashAlbum.getPhotoAssets(fetchOption);
2270  const fileAsset = await fetchResult.getFirstObject();
2271  let recoverFileUri = fileAsset.uri;
2272  trashAlbum.recover(recoverFileUri, (err) => {
2273    if (err != undefined) {
2274      console.error('trashAlbum.recover failed, message = ', err);
2275    } else {
2276      console.info('trashAlbum.recover successfully');
2277    }
2278  });
2279}
2280```
2281
2282### recover
2283
2284recover(uri: string): Promise&lt;void&gt;;
2285
2286Recovers files in a system album.
2287
2288**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.READ_AUDIO, and ohos.permission.WRITE_AUDIO
2289
2290**System capability**: SystemCapability.FileManagement.UserFileManager.Core
2291
2292**Parameters**
2293
2294| Name  | Type                     | Mandatory| Description      |
2295| -------- | ------------------------- | ---- | ---------- |
2296| uri | string | Yes  | Album URI.|
2297
2298**Return value**
2299
2300| Type                                   | Description             |
2301| --------------------------------------- | ----------------- |
2302| Promise&lt;void&gt;| Promise that returns no value.|
2303
2304**Example**
2305
2306```ts
2307import dataSharePredicates from '@ohos.data.dataSharePredicates';
2308
2309async function example() {
2310  console.info('privateAlbumRecoverDemoPromise');
2311  let albumList = await mgr.getPrivateAlbum(userFileManager.PrivateAlbumType.TYPE_TRASH);
2312  let predicates = new dataSharePredicates.DataSharePredicates();
2313  let fetchOption = {
2314    fetchColumns: [],
2315    predicates: predicates
2316  };
2317  const trashAlbum = await albumList.getFirstObject();
2318  let fetchResult = await trashAlbum.getPhotoAssets(fetchOption);
2319  const fileAsset = await fetchResult.getFirstObject();
2320  let recoverFileUri = fileAsset.uri;
2321  trashAlbum.recover(recoverFileUri).then(() => {
2322    console.info('trashAlbum.recover successfully');
2323  }).catch((err) => {
2324    console.error('trashAlbum.recover failed, message = ', err);
2325  });
2326}
2327```
2328
2329## MemberType
2330
2331Enumerates the member types.
2332
2333**System capability**: SystemCapability.FileManagement.UserFileManager.Core
2334
2335| Name |  Type|  Readable |  Writable |  Description |
2336| ----- |  ---- |  ---- |  ---- |  ---- |
2337| number |  number | Yes| Yes| The member is a number.|
2338| string |  string | Yes| Yes| The member is a string.|
2339| boolean |  boolean | Yes| Yes| The member is a Boolean value.|
2340
2341## ChangeEvent
2342
2343Enumerates the type of changes to observe.
2344
2345**System capability**: SystemCapability.FileManagement.UserFileManager.Core
2346
2347| Name |  Type|  Readable |  Writable |  Description|
2348| ----- |  ---- |  ---- |  ---- |  ---- |
2349| deviceChange |  string | Yes| Yes|  Device.|
2350| albumChange |  string | Yes| Yes|  Album.|
2351| imageChange |  string | Yes| Yes|  Image.|
2352| audioChange |  string | Yes| Yes|  Audio.|
2353| videoChange |  string | Yes| Yes|  Video.|
2354| remoteFileChange |  string | Yes| Yes|  Remote file.|
2355
2356## PeerInfo
2357
2358Defines information about a registered device.
2359
2360**System capability**: SystemCapability.FileManagement.UserFileManager.DistributedCore
2361
2362| Name      | Type                      | Readable| Writable| Description            |
2363| ---------- | -------------------------- | ---- | ---- | ---------------- |
2364| deviceName | string                     | Yes  | No  | Name of the registered device.  |
2365| networkId  | string                     | Yes  | No  | Network ID of the registered device.|
2366| isOnline   | boolean                    | Yes  | No  | Whether the registered device is online.        |
2367
2368## FileType
2369
2370Enumerates media file types.
2371
2372**System capability**: SystemCapability.FileManagement.UserFileManager.Core
2373
2374| Name |  Value|  Description|
2375| ----- |  ---- |  ---- |
2376| IMAGE |  1 |  Image.|
2377| VIDEO |  2 |  Video.|
2378| AUDIO |  3 |  Audio.|
2379
2380## PrivateAlbumType
2381
2382Enumerates the system album types.
2383
2384**System capability**: SystemCapability.FileManagement.UserFileManager.Core
2385
2386| Name   |  Value|   Description  |
2387| -----   |  ----  |   ----  |
2388| TYPE_FAVORITE |  0 |  Favorites.|
2389| TYPE_TRASH |  1 |  Recycle bin.|
2390
2391## AudioKey
2392
2393Defines the key information about an audio file.
2394
2395**System capability**: SystemCapability.FileManagement.UserFileManager.Core
2396
2397| Name         |   Value             | Description                                                      |
2398| ------------- | ------------------- | ---------------------------------------------------------- |
2399| URI           | uri                 | File URI.                                                  |
2400| DISPLAY_NAME  | display_name        | File name displayed.                                                  |
2401| DATE_ADDED    | date_added          | Date when the file was added. The value is the number of seconds elapsed since the Epoch time.            |
2402| 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.|
2403| TITLE         | title               | Title in the file.                                                  |
2404| ARTIST        | artist              | Author of the file.                                                  |
2405| AUDIOALBUM    | audio_album         | Audio album.                                                  |
2406| DURATION      | duration            | Duration, in ms.                                   |
2407| FAVORITE      | favorite            | Whether the file is added to favorites.                                                  |
2408
2409## ImageVideoKey
2410
2411Defines the key information about an image or video file.
2412
2413**System capability**: SystemCapability.FileManagement.UserFileManager.Core
2414
2415| Name         | Value             | Description                                                      |
2416| ------------- | ------------------- | ---------------------------------------------------------- |
2417| URI           | uri                 | File URI.                                                  |
2418| FILE_TYPE     | file_type           | Type of the file.                                             |
2419| DISPLAY_NAME  | display_name        | File name displayed.                                                  |
2420| DATE_ADDED    | date_added          | Date when the file was added. The value is the number of seconds elapsed since the Epoch time.            |
2421| 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.|
2422| TITLE         | title               | Title in the file.                                                  |
2423| DURATION      | duration            | Duration, in ms.                                   |
2424| WIDTH         | width               | Image width, in pixels.                                   |
2425| HEIGHT        | height              | Image height, in pixels.                                     |
2426| DATE_TAKEN    | date_taken          | Date when the file (photo) was taken. The value is the number of seconds elapsed since the Epoch time.               |
2427| ORIENTATION   | orientation         | Orientation of the image file.                                            |
2428| FAVORITE      | favorite            | Whether the file is added to favorites.                                                   |
2429
2430## AlbumKey
2431
2432Defines the key album information.
2433
2434**System capability**: SystemCapability.FileManagement.UserFileManager.Core
2435
2436| Name         | Value             | Description                                                      |
2437| ------------- | ------------------- | ---------------------------------------------------------- |
2438| URI           | uri                 | Album URI.                                                  |
2439| FILE_TYPE     | file_type           | Type of the file.                                             |
2440| ALBUM_NAME    | album_name          | Name of the album.                                                  |
2441| DATE_ADDED    | date_added          | Date when the file was added. The value is the number of seconds elapsed since the Epoch time.            |
2442| 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.|
2443
2444## FetchOptions
2445
2446Defines the options for fetching media files.
2447
2448**System capability**: SystemCapability.FileManagement.UserFileManager.Core
2449
2450| Name                  | Type               | Readable| Writable| Description                                             |
2451| ---------------------- | ------------------- | ---- |---- | ------------------------------------------------ |
2452| fetchColumns           | Array&lt;string&gt; | Yes  | Yes  | Columns to fetch. If this parameter is left empty, data is fetched by URI, name, and file type by default. For example,<br>**fetchColumns: "uri"**.|
2453| predicates           | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md) | Yes  | Yes  | Predicates that specify the fetch criteria.|
2454
2455## AlbumFetchOptions
2456
2457Defines the options for fetching an album.
2458
2459**System capability**: SystemCapability.FileManagement.UserFileManager.Core
2460
2461| Name                  | Type               | Readable| Writable| Description                                             |
2462| ---------------------- | ------------------- | ---- |---- | ------------------------------------------------ |
2463| predicates           | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md) | Yes  | Yes  | Predicates that specify the fetch criteria.|
2464