js-apis-userfilemanager.md 80.6 KB
Newer Older
1
# @ohos.filemanagement.userFileManager
A
Annie_wang 已提交
2

3 4 5 6 7 8
The **userFileManager** module provides user data management capabilities, including accessing and modifying user media data (audio and video clips, images, and files).

> **NOTE**
>
> 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.
> The APIs provided by this module are system APIs.
A
Annie_wang 已提交
9 10 11

## Modules to Import

12 13
```ts
import userFileManager from '@ohos.filemanagement.userFileManager';
A
Annie_wang 已提交
14 15 16 17 18 19
```

## userFileManager.getUserFileMgr

getUserFileMgr(context: Context): UserFileManager

20
Obtains a **UserFileManager** instance. This instance can be used to access and modify user media data (such as audio and video clips, images, and files).
A
Annie_wang 已提交
21 22 23 24 25 26 27 28 29

**Model restriction**: This API can be used only in the stage model.

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

**Parameters**

| Name | Type   | Mandatory| Description                      |
| ------- | ------- | ---- | -------------------------- |
30
| context | [Context](js-apis-inner-app-context.md) | Yes  | Context of the ability instance.|
A
Annie_wang 已提交
31 32 33 34 35 36 37 38 39 40 41

**Return value**

| Type                           | Description   |
| ----------------------------- | :---- |
| [UserFileManager](#userfilemanager) | **UserFileManager** instance obtained.|

**Example**

```ts
const context = getContext(this);
42
let mgr = userFileManager.getUserFileMgr(context);
A
Annie_wang 已提交
43 44
```

45 46 47
## UserFileManager

### getPhotoAssets
A
Annie_wang 已提交
48

49
getPhotoAssets(options: FetchOptions, callback: AsyncCallback<FetchResult<FileAsset>>): void;
A
Annie_wang 已提交
50 51


52 53
Obtains image and video assets. This API uses an asynchronous callback to return the result.

A
Annie_wang 已提交
54 55 56 57


**System capability**: SystemCapability.FileManagement.UserFileManager.Core

58
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
A
Annie_wang 已提交
59

60 61 62 63 64 65
**Parameters**

| Name  | Type                    | Mandatory| Description                     |
| -------- | ------------------------ | ---- | ------------------------- |
| options  | [FetchOptions](#fetchoptions)        | Yes  | Options for fetching the image and video assets.             |
| callback |  AsyncCallback<[FetchResult](#fetchresult)<[FileAsset](#fileasset)>> | Yes  | Callback invoked to return the image and video assets obtained.|
A
Annie_wang 已提交
66 67 68

**Example**

69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';

async function example() {
  console.info('getPhotoAssets');
  let predicates = new dataSharePredicates.DataSharePredicates();
  let fetchOptions = {
    fetchColumns: [],
    predicates: predicates
  };

  mgr.getPhotoAssets(fetchOptions, async (err, fetchResult) => {
    if (fetchResult != undefined) {
      console.info('fetchResult success');
      let fileAsset = await fetchResult.getFirstObject();
      if (fileAsset != undefined) {
        console.info("fileAsset.displayName :" + fileAsset.displayName);
      }
    } else {
      console.info('fetchResult fail' + err);
    }
  });
}
A
Annie_wang 已提交
92 93 94
```


95
### getPhotoAssets
A
Annie_wang 已提交
96

97
getPhotoAssets(options: FetchOptions): Promise<FetchResult<FileAsset>>;
A
Annie_wang 已提交
98

99
Obtains image and video assets. This API uses a promise to return the result.
A
Annie_wang 已提交
100 101 102

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

103 104
**Required permissions**: ohos.permission.READ_IMAGEVIDEO

A
Annie_wang 已提交
105 106
**Parameters**

107 108 109 110 111 112 113 114 115
| Name | Type               | Mandatory| Description            |
| ------- | ------------------- | ---- | ---------------- |
| options | [FetchOptions](#fetchoptions)   | Yes  | Options for fetching the image and video assets.    |

**Return value**

| Type                       | Description          |
| --------------------------- | -------------- |
| Promise<[FetchResult](#fetchresult)<[FileAsset](#fileasset)>> | Promise used to return the image and video assets obtained.|
A
Annie_wang 已提交
116 117 118 119

**Example**

```ts
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
import dataSharePredicates from '@ohos.data.dataSharePredicates';

async function example() {
  console.info('getPhotoAssets');
  let predicates = new dataSharePredicates.DataSharePredicates();
  let fetchOptions = {
    fetchColumns: [],
    predicates: predicates
  };
  try {
    var fetchResult = await mgr.getPhotoAssets(fetchOptions);
    if (fetchResult != undefined) {
      console.info('fetchResult success');
      let fileAsset = await fetchResult.getFirstObject();
      if (fileAsset != undefined) {
        console.info("fileAsset.displayName :" + fileAsset.displayName);
      }
    }
  } catch (err) {
    console.info('getPhotoAssets failed, message = ', err);
  }
A
Annie_wang 已提交
141 142
}
```
143
### createPhotoAsset
A
Annie_wang 已提交
144

145
createPhotoAsset(displayName: string, albumUri: string, callback: AsyncCallback<FileAsset>): void;
A
Annie_wang 已提交
146

147
Creates an image or video asset. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
148 149 150

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

151
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
A
Annie_wang 已提交
152

153
**Parameters**
A
Annie_wang 已提交
154

155 156 157 158 159
| Name  | Type                    | Mandatory| Description                     |
| -------- | ------------------------ | ---- | ------------------------- |
| displayName  | string        | Yes  | File name of the image or video to create.             |
| albumUri  | string        | Yes  | URI of the album where the image or video is located.             |
| callback |  AsyncCallback<[FileAsset](#fileasset)> | Yes  | Callback invoked to return the image or video created.|
A
Annie_wang 已提交
160 161 162 163

**Example**

```ts
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
import dataSharePredicates from '@ohos.data.dataSharePredicates';

async function example() {
  console.info('createPhotoAssetDemo');
  let predicates = new dataSharePredicates.DataSharePredicates();
  let fetchOptions = {
    predicates: predicates
  };
  let albums = await mgr.getPhotoAlbums(fetchOptions);
  let album = await albums.getFirstObject();
  let testFileName = "testFile" + Date.now() + ".jpg";
  mgr.createPhotoAsset(testFileName, album.albumUri, (err, fileAsset) => {
    if (fileAsset != undefined) {
      console.info('createPhotoAsset file displayName' + fileAsset.displayName);
      console.info('createPhotoAsset successfully');
    } else {
      console.info('createPhotoAsset failed, message = ', err);
A
Annie_wang 已提交
181
    }
182
  });
A
Annie_wang 已提交
183 184 185
}
```

186
### createPhotoAsset
A
Annie_wang 已提交
187

188
createPhotoAsset(displayName: string, callback: AsyncCallback<FileAsset>): void;
A
Annie_wang 已提交
189

190
Creates an image or video asset. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
191 192 193

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

194
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
A
Annie_wang 已提交
195 196 197 198 199

**Parameters**

| Name  | Type                    | Mandatory| Description                     |
| -------- | ------------------------ | ---- | ------------------------- |
200 201
| displayName  | string        | Yes  | File name of the image or video to create.             |
| callback |  AsyncCallback<[FileAsset](#fileasset)> | Yes  | Callback invoked to return the image or video created.|
A
Annie_wang 已提交
202 203 204 205

**Example**

```ts
206 207 208 209 210 211 212 213 214 215 216
async function example() {
  console.info('createPhotoAssetDemo');
  let testFileName = "testFile" + Date.now() + ".jpg";
  mgr.createPhotoAsset(testFileName, (err, fileAsset) => {
    if (fileAsset != undefined) {
      console.info('createPhotoAsset file displayName' + fileAsset.displayName);
      console.info('createPhotoAsset successfully');
    } else {
      console.info('createPhotoAsset failed, message = ', err);
    }
  });
A
Annie_wang 已提交
217 218 219
}
```

220
### createPhotoAsset
A
Annie_wang 已提交
221

222
createPhotoAsset(displayName: string, albumUri?: string): Promise<FileAsset>;
A
Annie_wang 已提交
223

224
Creates an image or video asset. This API uses a promise to return the result.
A
Annie_wang 已提交
225 226 227

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

228
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
A
Annie_wang 已提交
229 230 231

**Parameters**

232 233 234 235
| Name  | Type                    | Mandatory| Description                     |
| -------- | ------------------------ | ---- | ------------------------- |
| displayName  | string        | Yes  | File name of the image or video to create.             |
| albumUri  | string        | No  | URI of the album where the image or video is located.             |
A
Annie_wang 已提交
236 237 238 239 240

**Return value**

| Type                       | Description          |
| --------------------------- | -------------- |
241
| Promise<[FileAsset](#fileasset)> | Promise used to return the image or video created.|
A
Annie_wang 已提交
242 243 244 245

**Example**

```ts
246 247 248 249 250 251 252 253 254 255
async function example() {
  console.info('createPhotoAssetDemo');
  try {
    let testFileName = "testFile" + Date.now() + ".jpg";
    let fileAsset = await mgr.createPhotoAsset(testFileName);
    console.info('createPhotoAsset file displayName' + fileAsset.displayName);
    console.info('createPhotoAsset successfully');
  } catch (err) {
    console.info('createPhotoAsset failed, message = ', err);
  }
A
Annie_wang 已提交
256 257 258
}
```

259
### getPhotoAlbums
A
Annie_wang 已提交
260

261
getPhotoAlbums(options: AlbumFetchOptions, callback: AsyncCallback<FetchResult<Album>>): void;
A
Annie_wang 已提交
262

263 264

Obtains image and video albums. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
265 266 267

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

268 269
**Required permissions**: ohos.permission.READ_IMAGEVIDEO

A
Annie_wang 已提交
270 271
**Parameters**

272 273 274 275
| Name  | Type                    | Mandatory| Description                     |
| -------- | ------------------------ | ---- | ------------------------- |
| options  | [AlbumFetchOptions](#albumfetchoptions)        | Yes  | Options for fetching the albums.             |
| callback |  AsyncCallback<[FetchResult](#fetchresult)<[Album](#album)>> | Yes  | Callback invoked to return the albums obtained.|
A
Annie_wang 已提交
276 277 278 279

**Example**

```ts
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
import dataSharePredicates from '@ohos.data.dataSharePredicates';

async function example() {
  console.info('getPhotoAlbumsDemo');
  let predicates = new dataSharePredicates.DataSharePredicates();
  let albumFetchOptions = {
    predicates: predicates
  };

  mgr.getPhotoAlbums(albumFetchOptions, (err, fetchResult) => {
    if (fetchResult != undefined) {
      console.info('albums.count = ' + fetchResult.getCount());
      fetchResult.getFirstObject((err, album) => {
        if (album != undefined) {
          console.info('first album.albumName = ' + album.albumName);
        } else {
          console.info('album is undefined, err = ', err);
        }
      });
    } else {
      console.info('getPhotoAlbums fail, message = ', err);
    }
  });
A
Annie_wang 已提交
303 304 305
}
```

306
### getPhotoAlbums
A
Annie_wang 已提交
307

308
getPhotoAlbums(options: AlbumFetchOptions): Promise<FetchResult<Album>>;
A
Annie_wang 已提交
309

310
Obtains image and video albums. This API uses a promise to return the result.
A
Annie_wang 已提交
311 312 313

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

314 315
**Required permissions**: ohos.permission.READ_IMAGEVIDEO

A
Annie_wang 已提交
316 317
**Parameters**

318 319 320 321 322 323 324 325 326
| Name  | Type                    | Mandatory| Description                     |
| -------- | ------------------------ | ---- | ------------------------- |
| options  | [AlbumFetchOptions](#albumfetchoptions)        | Yes  | Options for fetching the albums.             |

**Return value**

| Type                       | Description          |
| --------------------------- | -------------- |
| Promise<[FetchResult](#fetchresult)<[Album](#album)>> | Promise used to return the albums obtained.|
A
Annie_wang 已提交
327 328 329 330

**Example**

```ts
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
import dataSharePredicates from '@ohos.data.dataSharePredicates';

async function example() {
  console.info('getPhotoAlbumsDemo');
  let predicates = new dataSharePredicates.DataSharePredicates();
  let albumFetchOptions = {
    predicates: predicates
  };
  try {
    let fetchResult = await mgr.getPhotoAlbums(albumFetchOptions);
    console.info('album.count = ' + fetchResult.getCount());
    const album = await fetchResult.getFirstObject();
    console.info('first album.albumName = ' + album.albumName);
  } catch (err) {
    console.info('getPhotoAlbums fail, message = ' + err);
  }
A
Annie_wang 已提交
347 348 349
}
```

350
### getPrivateAlbum
A
Annie_wang 已提交
351

352
getPrivateAlbum(type: PrivateAlbumType, callback: AsyncCallback<FetchResult<PrivateAlbum>>): void;
A
Annie_wang 已提交
353 354


355
Obtains the system album. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
356 357 358

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

359
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
A
Annie_wang 已提交
360 361 362

**Parameters**

363 364 365 366
| Name  | Type                    | Mandatory| Description                     |
| -------- | ------------------------ | ---- | ------------------------- |
| type  | [PrivateAlbumType](#privatealbumtype)        | Yes  | Type of the album to obtain.             |
| callback |  AsyncCallback<[FetchResult](#fetchresult)<[PrivateAlbum](#privatealbum)>> | Yes  | Callback invoked to return the album obtained.|
A
Annie_wang 已提交
367 368 369 370

**Example**

```ts
371 372 373 374 375 376 377 378 379 380
async function example() {
  console.info('getPrivateAlbumDemo');
  mgr.getPrivateAlbum(userFileManager.PrivateAlbumType.TYPE_TRASH, async (err, fetchResult) => {
    if (fetchResult != undefined) {
      let trashAlbum = await fetchResult.getFirstObject();
      console.info('first album.albumName = ' + trashAlbum.albumName);
    } else {
      console.info('getPrivateAlbum failed. message = ', err);
    }
  });
A
Annie_wang 已提交
381 382 383
}
```

384
### getPrivateAlbum
A
Annie_wang 已提交
385

386
getPrivateAlbum(type: PrivateAlbumType): Promise<FetchResult<PrivateAlbum>>;
A
Annie_wang 已提交
387 388


389
Obtains the system album. This API uses a promise to return the result.
A
Annie_wang 已提交
390 391 392

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

393
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
A
Annie_wang 已提交
394 395 396

**Parameters**

397 398 399
| Name  | Type                    | Mandatory| Description                     |
| -------- | ------------------------ | ---- | ------------------------- |
| type  | [PrivateAlbumType](#privatealbumtype)        | Yes  | Type of the album to obtain.             |
A
Annie_wang 已提交
400 401 402

**Return value**

403 404 405
| Type                       | Description          |
| --------------------------- | -------------- |
| Promise<[FetchResult](#fetchresult)<[PrivateAlbum](#privatealbum)>> | Promise used to return the album obtained.|
A
Annie_wang 已提交
406 407 408 409

**Example**

```ts
410 411 412 413 414 415 416 417 418
async function example() {
  console.info('getPrivateAlbumDemo');
  try {
    var fetchResult = await mgr.getPrivateAlbum(userFileManager.PrivateAlbumType.TYPE_TRASH);
    let trashAlbum = await fetchResult.getFirstObject();
    console.info('first album.albumName = ' + trashAlbum.albumName);
  } catch (err) {
    console.info('getPrivateAlbum failed. message = ', err);
  }
A
Annie_wang 已提交
419 420 421
}
```

422
### getAudioAssets
A
Annie_wang 已提交
423

424
getAudioAssets(options: FetchOptions, callback: AsyncCallback<FetchResult<FileAsset>>): void;
A
Annie_wang 已提交
425 426


427
Obtains audio assets. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
428 429 430

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

431
**Required permissions**: ohos.permission.READ_AUDIO
A
Annie_wang 已提交
432 433 434

**Parameters**

435 436 437 438
| Name  | Type                    | Mandatory| Description                     |
| -------- | ------------------------ | ---- | ------------------------- |
| options  | [FetchOptions](#fetchoptions)        | Yes  | Options for fetching the audio assets.             |
| callback |  AsyncCallback<[FetchResult](#fetchresult)<[FileAsset](#fileasset)>> | Yes  | Callback invoked to return the audio assets obtained.|
A
Annie_wang 已提交
439 440 441 442

**Example**

```ts
443
import dataSharePredicates from '@ohos.data.dataSharePredicates';
A
Annie_wang 已提交
444

445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461
async function example() {
  console.info('getAudioAssets');
  let predicates = new dataSharePredicates.DataSharePredicates();
  let fetchOptions = {
    fetchColumns: [],
    predicates: predicates
  };

  mgr.getAudioAssets(fetchOptions, async (err, fetchResult) => {
    if (fetchResult != undefined) {
      console.info('fetchFileResult success');
      let fileAsset = await fetchResult.getFirstObject();
      if (fileAsset != undefined) {
        console.info("fileAsset.displayName :" + fileAsset.displayName);
      }
    } else {
      console.info('fetchFileResult fail' + err);
A
Annie_wang 已提交
462
    }
463
  });
A
Annie_wang 已提交
464 465 466
}
```

467
### getAudioAssets
A
Annie_wang 已提交
468

469
getAudioAssets(options: FetchOptions): Promise<FetchResult<FileAsset>>;
A
Annie_wang 已提交
470 471


472
Obtains audio assets. This API uses a promise to return the result.
A
Annie_wang 已提交
473 474 475

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

476
**Required permissions**: ohos.permission.READ_AUDIO
A
Annie_wang 已提交
477 478 479

**Parameters**

480 481 482
| Name  | Type                    | Mandatory| Description                     |
| -------- | ------------------------ | ---- | ------------------------- |
| options  | [FetchOptions](#fetchoptions)        | Yes  | Options for fetching the audio assets.             |
A
Annie_wang 已提交
483 484 485

**Return value**

486 487 488
| Type                       | Description          |
| --------------------------- | -------------- |
| Promise<[FetchResult](#fetchresult)<[FileAsset](#fileasset)>> | Promise used to return the audio assets obtained.|
A
Annie_wang 已提交
489 490 491 492

**Example**

```ts
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512
import dataSharePredicates from '@ohos.data.dataSharePredicates';

async function example() {
  console.info('getAudioAssets');
  let predicates = new dataSharePredicates.DataSharePredicates();
  let fetchOptions = {
    fetchColumns: [],
    predicates: predicates
  };
  try {
    var fetchResult = await mgr.getAudioAssets(fetchOptions);
  } catch (err) {
    console.info('getAudioAssets failed, message = ', err);
  }

  if (fetchResult != undefined) {
    console.info('fetchFileResult success');
    let fileAsset = await fetchResult.getFirstObject();
    if (fileAsset != undefined) {
      console.info("fileAsset.displayName :" + fileAsset.displayName);
A
Annie_wang 已提交
513
    }
514
  }
A
Annie_wang 已提交
515 516
}
```
517
### delete
A
Annie_wang 已提交
518

519
delete(uri: string, callback: AsyncCallback<void>): void;
A
Annie_wang 已提交
520

521
Deletes a media file. This API uses an asynchronous callback to return the result. The deleted file is moved to the recycle bin.
A
Annie_wang 已提交
522

523
**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.READ_AUDIO, and ohos.permission.WRITE_AUDIO
A
Annie_wang 已提交
524 525 526 527 528

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

**Parameters**

529 530 531 532
| Name  | Type                     | Mandatory| Description      |
| -------- | ------------------------- | ---- | ---------- |
| uri | string | Yes  | URI of the media file to delete.|
| callback | AsyncCallback<void> | Yes  | Callback that returns no value.|
A
Annie_wang 已提交
533 534 535 536

**Example**

```ts
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563
import dataSharePredicates from '@ohos.data.dataSharePredicates';

async function example() {
  console.info('deleteAssetDemo');
  let predicates = new dataSharePredicates.DataSharePredicates();
  let fetchOptions = {
    fetchColumns: [],
    predicates: predicates
  };
  try {
    const fetchResult = await mgr.getPhotoAssets(fetchOptions);
    var asset = await fetchResult.getFirstObject();
  } catch (err) {
    console.info('fetch failed, message =', err);
  }

  if (asset == undefined) {
    console.error('asset not exist');
    return;
  }
  mgr.delete(asset.uri, (err) => {
    if (err == undefined) {
      console.info("delete successfully");
    } else {
      console.info("delete failed with error:" + err);
    }
  });
A
Annie_wang 已提交
564 565
}
```
566
### delete
A
Annie_wang 已提交
567

568
delete(uri: string): Promise<void>;
A
Annie_wang 已提交
569

570
Deletes a media file. This API uses a promise to return the result. The deleted file is moved to the recycle bin.
A
Annie_wang 已提交
571

572
**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.READ_AUDIO, and ohos.permission.WRITE_AUDIO
A
Annie_wang 已提交
573 574 575 576 577

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

**Parameters**

578 579 580
| Name  | Type                     | Mandatory| Description      |
| -------- | ------------------------- | ---- | ---------- |
| uri | string | Yes  | URI of the media file to delete.|
A
Annie_wang 已提交
581 582 583

**Return value**

584 585 586
| Type                                   | Description             |
| --------------------------------------- | ----------------- |
| Promise<void>| Promise that returns no value.|
A
Annie_wang 已提交
587 588 589 590

**Example**

```ts
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616
import dataSharePredicates from '@ohos.data.dataSharePredicates';

async function example() {
  console.info('deleteDemo');
  let predicates = new dataSharePredicates.DataSharePredicates();
  let fetchOptions = {
    fetchColumns: [],
    predicates: predicates
  };
  try {
    const fetchResult = await mgr.getPhotoAssets(fetchOptions);
    var asset = await fetchResult.getFirstObject();
  } catch (err) {
    console.info('fetch failed, message =', err);
  }

  if (asset == undefined) {
    console.error('asset not exist');
    return;
  }
  try {
    await mgr.delete(asset.uri);
    console.info("delete successfully");
  } catch (err) {
    console.info("delete failed with error:" + err);
  }
A
Annie_wang 已提交
617 618 619
}
```

620
### on
A
Annie_wang 已提交
621

622
on(type: ChangeEvent, callback: Callback<void>): void
A
Annie_wang 已提交
623

624
Subscribes to changes of the file management library. This API uses a callback to return the result.
A
Annie_wang 已提交
625 626 627 628 629

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

**Parameters**

630 631 632 633
| Name  | Type                | Mandatory| Description                                                        |
| -------- | -------------------- | ---- | ------------------------------------------------------------ |
| 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.|
| callback | Callback&lt;void&gt; | Yes  | Callback that returns no value.                                                  |
A
Annie_wang 已提交
634 635 636 637

**Example**

```ts
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661
async function example() {
  console.info('onDemo');
  let count = 0;
  mgr.on('imageChange', () => {
    count++;
    // Image file changed. Do something.
  });
  try {
    let testFileName = "testFile" + Date.now() + ".jpg";
    let fileAsset = await mgr.createPhotoAsset(testFileName);
    console.info('createPhotoAsset file displayName' + fileAsset.displayName);
    console.info('createPhotoAsset successfully');
  } catch (err) {
    console.info('createPhotoAsset failed, message = ' + err);
  }
  //sleep 1s
  if (count > 0) {
    console.info("onDemo success");
  } else {
    console.info("onDemo fail");
  }
  mgr.off('imageChange', () => {
    // Unsubscription succeeds.
  });
A
Annie_wang 已提交
662 663 664
}
```

665
### off
A
Annie_wang 已提交
666

667
off(type: ChangeEvent, callback?: Callback&lt;void&gt;): void
A
Annie_wang 已提交
668

669
Unsubscribes from changes of the file management library. This API uses a callback to return the result.
A
Annie_wang 已提交
670 671 672 673 674

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

**Parameters**

675 676 677 678
| Name  | Type                | Mandatory| Description                                                        |
| -------- | -------------------- | ---- | ------------------------------------------------------------ |
| 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.|
| callback | Callback&lt;void&gt; | No  | Callback that returns no value.                                                  |
A
Annie_wang 已提交
679 680 681 682

**Example**

```ts
683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708
async function example() {
  console.info('offDemo');
  let count = 0;
  mgr.on('imageChange', () => {
    count++;
    // Image file changed. Do something.
  });

  mgr.off('imageChange', () => {
    // Unsubscription succeeds.
  });

  try {
    let testFileName = "testFile" + Date.now() + ".jpg";
    let fileAsset = await mgr.createPhotoAsset(testFileName);
    console.info('createPhotoAsset file displayName' + fileAsset.displayName);
    console.info('createPhotoAsset successfully');
  } catch (err) {
    console.info('createPhotoAsset failed, message = ' + err);
  }
  //sleep 1s
  if (count == 0) {
    console.info("offDemo success");
  } else {
    console.info("offDemo fail");
  }
A
Annie_wang 已提交
709 710 711 712 713
}
```

### getActivePeers

714
getActivePeers(callback: AsyncCallback&lt;Array&lt;PeerInfo&gt;&gt;): void;
A
Annie_wang 已提交
715 716 717 718 719 720 721 722 723

Obtains information about online peer devices. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.FileManagement.UserFileManager.DistributedCore

**Parameters**

| Name  | Type                             | Mandatory| Description        |
| -------- | --------------------------------- | ---- | ------------ |
724
| callback | AsyncCallback&lt;Array&lt;[PeerInfo](#peerinfo)&gt;&gt; | Yes  | Callback invoked to return the online peer device list.|
A
Annie_wang 已提交
725 726 727 728

**Example**

```ts
729 730 731 732 733 734 735 736 737 738 739 740
async function example() {
  console.info('getActivePeersDemo');
  mgr.getActivePeers((err, devicesInfo) => {
    if (devicesInfo != undefined) {
      console.log('getActivePeers succeed.');
      for (let i = 0; i < devicesInfo.length; i++) {
        console.info('get distributed info ' + devicesInfo[i].deviceName + devicesInfo[i].networkId);
      }
    } else {
      console.info('getActivePeers failed. message = ', err);
    }
  });
A
Annie_wang 已提交
741 742 743 744 745
}
```

### getActivePeers

746
getActivePeers(): Promise&lt;Array&lt;PeerInfo&gt;&gt;;
A
Annie_wang 已提交
747 748 749 750 751 752 753 754 755

Obtains information about online peer devices. This API uses a promise to return the result.

**System capability**: SystemCapability.FileManagement.UserFileManager.DistributedCore

**Return value**

| Type                       | Description                         |
| --------------------------- | ----------------------------- |
756
| Promise&lt;Array&lt;[PeerInfo](#peerinfo)&gt;&gt; | Promise used to return the online device list.|
A
Annie_wang 已提交
757 758 759 760

**Example**

```ts
761 762 763 764 765 766 767 768 769 770 771
async function example() {
  console.info('getActivePeersDemo');
  try {
    var devicesInfo = await mgr.getActivePeers();
  } catch (err) {
    console.info('getActivePeers failed. message = ', err);
  }
  if (devicesInfo != undefined) {
    console.log('getActivePeers succeed.');
    for (let i = 0; i < devicesInfo.length; i++) {
      console.info('get distributed info ' + devicesInfo[i].deviceName + devicesInfo[i].networkId);
A
Annie_wang 已提交
772
    }
773 774 775
  } else {
    console.info('get distributed fail');
  }
A
Annie_wang 已提交
776 777 778 779 780
}
```

### getAllPeers

781
getAllPeers(callback: AsyncCallback&lt;Array&lt;PeerInfo&gt;&gt;): void;
A
Annie_wang 已提交
782 783 784 785 786 787 788 789 790

Obtains information about all peer devices. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.FileManagement.UserFileManager.DistributedCore

**Parameters**

| Name  | Type                             | Mandatory| Description        |
| -------- | --------------------------------- | ---- | ------------ |
791
| callback | AsyncCallback&lt;Array&lt;[PeerInfo](#peerinfo)&gt;&gt; | Yes  | Callback invoked to return the online peer device list.|
A
Annie_wang 已提交
792 793 794 795

**Example**

```ts
796 797 798 799 800 801 802 803 804 805 806 807
async function example() {
  console.info('getAllPeersDemo');
  mgr.getAllPeers((err, devicesInfo) => {
    if (devicesInfo != undefined) {
      console.log('getAllPeers succeed.');
      for (let i = 0; i < devicesInfo.length; i++) {
        console.info('get distributed info ' + devicesInfo[i].deviceName + devicesInfo[i].networkId);
      }
    } else {
      console.info('getAllPeers failed. message = ', err);
    }
  });
A
Annie_wang 已提交
808 809 810 811 812
}
```

### getAllPeers

813
getAllPeers(): Promise&lt;Array&lt;PeerInfo&gt;&gt;;
A
Annie_wang 已提交
814 815 816 817 818 819 820 821 822

Obtains information about all peer devices. This API uses a promise to return the result.

**System capability**: SystemCapability.FileManagement.UserFileManager.DistributedCore

**Return value**

| Type                       | Description                         |
| --------------------------- | ----------------------------- |
823
| Promise&lt;Array&lt;[PeerInfo](#peerinfo)&gt;&gt; | Promise used to return the peer device list.|
A
Annie_wang 已提交
824 825 826 827

**Example**

```ts
828 829 830 831 832 833 834 835 836 837 838
async function example() {
  console.info('getAllPeersDemo');
  try {
    var devicesInfo = await mgr.getAllPeers();
  } catch (err) {
    console.info('getAllPeers failed. message = ', err);
  }
  if (devicesInfo != undefined) {
    console.log('getAllPeers succeed.');
    for (let i = 0; i < devicesInfo.length; i++) {
      console.info('get distributed info ' + devicesInfo[i].deviceName + devicesInfo[i].networkId);
A
Annie_wang 已提交
839
    }
840 841 842
  } else {
    console.info('get distributed fail');
  }
A
Annie_wang 已提交
843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858
}
```

### release

release(callback: AsyncCallback&lt;void&gt;): void

Releases this **UserFileManager** instance. This API uses an asynchronous callback to return the result.
Call this API when the APIs in the **UserFileManager** instance are no longer used.

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

**Parameters**

| Name  | Type                     | Mandatory| Description                |
| -------- | ------------------------- | ---- | -------------------- |
859
| callback | AsyncCallback&lt;void&gt; | Yes  | Callback that returns no value.|
A
Annie_wang 已提交
860 861 862 863

**Example**

```ts
864 865 866 867 868 869 870 871 872
async function example() {
  console.info('releaseDemo');
  mgr.release((err) => {
    if (err != undefined) {
      console.info('release failed. message = ', err);
    } else {
      console.info('release ok.');
    }
  });
A
Annie_wang 已提交
873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888
}
```

### release

release(): Promise&lt;void&gt;

Releases this **UserFileManager** instance. This API uses a promise to return the result.
Call this API when the APIs in the **UserFileManager** instance are no longer used.

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

**Return value**

| Type               | Description                             |
| ------------------- | --------------------------------- |
889
| Promise&lt;void&gt; | Promise that returns no value.|
A
Annie_wang 已提交
890 891 892 893

**Example**

```ts
894 895 896 897 898 899 900 901
async function example() {
  console.info('releaseDemo');
  try {
    await mgr.release();
    console.info('release ok.');
  } catch (err) {
    console.info('release failed. message = ', err);
  }
A
Annie_wang 已提交
902 903 904 905 906 907 908 909 910 911 912 913 914 915
}
```

## FileAsset

Provides APIs for encapsulating file asset attributes.

### Attributes

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

| Name                     | Type                    | Readable| Writable| Description                                                  |
| ------------------------- | ------------------------ | ---- | ---- | ------------------------------------------------------ |
| uri                       | string                   | Yes  | No  | File asset URI, for example, **dataability:///media/image/2**.        |
916
| fileType   | [FileType](#filetype) | Yes  | No  | Type of the file.                                              |
A
Annie_wang 已提交
917 918 919
| displayName               | string                   | Yes  | Yes  | File name, including the file name extension, to display.                                |


920
### get
A
Annie_wang 已提交
921

922
get(member: string): MemberType;
A
Annie_wang 已提交
923

924
Obtains the value of a **FileAsset** parameter.
A
Annie_wang 已提交
925 926 927 928 929

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

**Parameters**

930 931 932
| Name     | Type                       | Mandatory  | Description   |
| -------- | ------------------------- | ---- | ----- |
| member | string | Yes   | Name of the parameter to obtain, for example, **ImageVideoKey.URI**.|
A
Annie_wang 已提交
933 934 935

**Example**

936 937 938
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';

A
Annie_wang 已提交
939
async function example() {
940 941 942 943 944 945
  console.info('fileAssetGetDemo');
  try {
    let predicates = new dataSharePredicates.DataSharePredicates();
    let fetchOption = {
      fetchColumns: [],
      predicates: predicates
A
Annie_wang 已提交
946
    };
947 948 949 950 951 952 953 954
    let fetchResult = await mgr.getPhotoAssets(fetchOption);
    let fileAsset = await fetchResult.getFirstObject();
    let title = userFileManager.ImageVideoKey.TITLE;
    let fileAssetTitle = fileAsset.get(title.toString());
    console.info('fileAsset Get fileAssetTitle = ', fileAssetTitle);
  } catch (err) {
    console.info('release failed. message = ', err);
  }
A
Annie_wang 已提交
955 956 957
}
```

958
### set
A
Annie_wang 已提交
959

960
set(member: string, value: string): void;
A
Annie_wang 已提交
961

962
Sets a **FileAsset** parameter.
A
Annie_wang 已提交
963 964 965

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

966
**Parameters**
A
Annie_wang 已提交
967

968 969 970 971
| Name     | Type                       | Mandatory  | Description   |
| -------- | ------------------------- | ---- | ----- |
| member | string | Yes   | Name of the parameter to set, for example, **ImageVideoKey.URI**.|
| value | string | Yes   | Value to set. Only the value of **ImageVideoKey.TITLE** can be changed.|
A
Annie_wang 已提交
972 973 974

**Example**

975 976 977
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';

A
Annie_wang 已提交
978
async function example() {
979 980 981 982 983 984
  console.info('fileAssetSetDemo');
  try {
    let predicates = new dataSharePredicates.DataSharePredicates();
    let fetchOption = {
      fetchColumns: [],
      predicates: predicates
A
Annie_wang 已提交
985
    };
986 987 988 989 990 991 992
    let fetchResult = await mgr.getPhotoAssets(fetchOption);
    let fileAsset = await fetchResult.getFirstObject();
    let title = userFileManager.ImageVideoKey.TITLE;
    fileAsset.set(title.toString(), "newTitle");
  } catch (err) {
    console.info('release failed. message = ', err);
  }
A
Annie_wang 已提交
993 994 995 996 997 998 999 1000 1001
}
```

### commitModify

commitModify(callback: AsyncCallback&lt;void&gt;): void

Commits the modification on the file metadata to the database. This API uses an asynchronous callback to return the result.

1002
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.WRITE_AUDIO
A
Annie_wang 已提交
1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

**Parameters**

| Name     | Type                       | Mandatory  | Description   |
| -------- | ------------------------- | ---- | ----- |
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback that returns no value.|

**Example**

1014 1015 1016
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';

A
Annie_wang 已提交
1017
async function example() {
1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037
  console.info('commitModifyDemo');
  let predicates = new dataSharePredicates.DataSharePredicates();
  let fetchOption = {
    fetchColumns: [],
    predicates: predicates
  };
  let fetchResult = await mgr.getPhotoAssets(fetchOption);
  let fileAsset = await fetchResult.getFirstObject();
  let title = userFileManager.ImageVideoKey.TITLE;
  let fileAssetTitle = fileAsset.get(title.toString());
  console.info('fileAsset Get fileAssetTitle = ', fileAssetTitle);
  fileAsset.set(title.toString(), "newTitle");
  fileAsset.commitModify((err) => {
    if (err == undefined) {
      let newFileAssetTitle = fileAsset.get(title.toString());
      console.info('fileAsset Get newFileAssetTitle = ', newFileAssetTitle);
    } else {
      console.info('commitModify failed, message =', err);
    }
  });
A
Annie_wang 已提交
1038 1039 1040 1041 1042 1043 1044 1045 1046
}
```

### commitModify

commitModify(): Promise&lt;void&gt;

Commits the modification on the file metadata to the database. This API uses a promise to return the result.

1047
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.WRITE_AUDIO
A
Annie_wang 已提交
1048 1049 1050 1051 1052 1053 1054 1055 1056

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

**Return value**

| Type                 | Description        |
| ------------------- | ---------- |
| Promise&lt;void&gt; | Promise that returns no value.|

1057 1058 1059 1060
**Example** 

```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';
A
Annie_wang 已提交
1061 1062

async function example() {
1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081
  console.info('commitModifyDemo');
  let predicates = new dataSharePredicates.DataSharePredicates();
  let fetchOption = {
    fetchColumns: [],
    predicates: predicates
  };
  let fetchResult = await mgr.getPhotoAssets(fetchOption);
  let fileAsset = await fetchResult.getFirstObject();
  let title = userFileManager.ImageVideoKey.TITLE;
  let fileAssetTitle = fileAsset.get(title.toString());
  console.info('fileAsset Get fileAssetTitle = ', fileAssetTitle);
  fileAsset.set(title.toString(), "newTitle");
  try {
    await fileAsset.commitModify();
    let newFileAssetTitle = fileAsset.get(title.toString());
    console.info('fileAsset Get newFileAssetTitle = ', newFileAssetTitle);
  } catch (err) {
    console.info('release failed. message = ', err);
  }
A
Annie_wang 已提交
1082 1083 1084 1085 1086 1087 1088 1089 1090
}
```

### open

open(mode: string, callback: AsyncCallback&lt;number&gt;): void

Opens this file asset. This API uses an asynchronous callback to return the result.

1091 1092 1093
>**NOTE**
>
>The write operations are mutually exclusive. After a write operation is complete, you must call **close** to release the resource.
A
Annie_wang 已提交
1094

1095
**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.READ_AUDIO, ohos.permission.WRITE_IMAGEVIDEO, or ohos.permission.WRITE_AUDIO
A
Annie_wang 已提交
1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108


**System capability**: SystemCapability.FileManagement.UserFileManager.Core

**Parameters**

| Name     | Type                         | Mandatory  | Description                                 |
| -------- | --------------------------- | ---- | ----------------------------------- |
| mode     | string                      | Yes   | File open mode, which can be **r** (read-only), **w** (write-only), or **rw** (read-write).|
| callback | AsyncCallback&lt;number&gt; | Yes   | Callback used to return the file handle.                           |

**Example**

1109
```ts
A
Annie_wang 已提交
1110
async function example() {
1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121
  console.info('openDemo');
   let testFileName = "testFile" + Date.now() + ".jpg";
  const fileAsset = await mgr.createPhotoAsset(testFileName);
  fileAsset.open('rw', (err, fd) => {
    if (fd != undefined) {
      console.info('File fd' + fd);
      fileAsset.close(fd);
    } else {
      console.info('File err' + err);
    }
  });
A
Annie_wang 已提交
1122 1123 1124 1125 1126 1127 1128 1129 1130
}
```

### open

open(mode: string): Promise&lt;number&gt;

Opens this file asset. This API uses a promise to return the result.

1131 1132 1133
>**NOTE**
>
>The write operations are mutually exclusive. After a write operation is complete, you must call **close** to release the resource.
A
Annie_wang 已提交
1134

1135
**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.READ_AUDIO, ohos.permission.WRITE_IMAGEVIDEO, or ohos.permission.WRITE_AUDIO
A
Annie_wang 已提交
1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

**Parameters**

| Name | Type    | Mandatory  | Description                                 |
| ---- | ------ | ---- | ----------------------------------- |
| mode | string | Yes   | File open mode, which can be **r** (read-only), **w** (write-only), or **rw** (read-write).|

**Return value**

| Type                   | Description           |
| --------------------- | ------------- |
| Promise&lt;number&gt; | Promise used to return the file handle.|

**Example**

1153
```ts
A
Annie_wang 已提交
1154
async function example() {
1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168
  console.info('openDemo');
  try {
    let testFileName = "testFile" + Date.now() + ".jpg";
    const fileAsset = await mgr.createPhotoAsset(testFileName);
    let fd = await fileAsset.open('rw');
    if (fd != undefined) {
      console.info('File fd' + fd);
      fileAsset.close(fd);
    } else {
      console.info(' open File fail');
    }
  } catch (err) {
    console.info('open Demo err' + err);
  }
A
Annie_wang 已提交
1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188
}
```

### close

close(fd: number, callback: AsyncCallback&lt;void&gt;): void

Closes this file asset. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

**Parameters**

| Name     | Type                       | Mandatory  | Description   |
| -------- | ------------------------- | ---- | ----- |
| fd       | number                    | Yes   | File descriptor.|
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback that returns no value.|

**Example**

1189 1190 1191
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';

A
Annie_wang 已提交
1192
async function example() {
1193 1194 1195 1196 1197 1198
  console.info('closeDemo');
  try {
    let predicates = new dataSharePredicates.DataSharePredicates();
    let fetchOption = {
      fetchColumns: [],
      predicates: predicates
A
Annie_wang 已提交
1199
    };
1200 1201 1202 1203 1204 1205 1206 1207 1208 1209
    let fetchResult = await mgr.getPhotoAssets(fetchOption);
    const fileAsset = await fetchResult.getFirstObject();
    let fd = await fileAsset.open('rw');
    console.info('file fd', fd);
    fileAsset.close(fd, (err) => {
      if (err == undefined) {
        console.info('asset close succeed.');
      } else {
        console.info('close failed, message = ' + err);
      }
A
Annie_wang 已提交
1210
    });
1211 1212 1213
  } catch (err) {
    console.info('close failed, message = ' + err);
  }
A
Annie_wang 已提交
1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238
}
```

### close

close(fd: number): Promise&lt;void&gt;

Closes this file asset. This API uses a promise to return the result.

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

**Parameters**

| Name | Type    | Mandatory  | Description   |
| ---- | ------ | ---- | ----- |
| fd   | number | Yes   | File descriptor.|

**Return value**

| Type                 | Description        |
| ------------------- | ---------- |
| Promise&lt;void&gt; | Promise that returns no value.|

**Example**

1239 1240 1241
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';

A
Annie_wang 已提交
1242
async function example() {
1243 1244 1245 1246 1247 1248
  console.info('closeDemo');
  try {
    let predicates = new dataSharePredicates.DataSharePredicates();
    let fetchOption = {
      fetchColumns: [],
      predicates: predicates
A
Annie_wang 已提交
1249
    };
1250 1251 1252 1253 1254 1255 1256 1257 1258
    let fetchResult = await mgr.getPhotoAssets(fetchOption);
    const asset = await fetchResult.getFirstObject();
    let fd = await asset.open('rw');
    console.info('file fd', fd);
    await asset.close(fd);
    console.info('asset close succeed.');
  } catch (err) {
    console.info('close failed, message = ' + err);
  }
A
Annie_wang 已提交
1259 1260 1261 1262 1263 1264 1265 1266 1267
}
```

### getThumbnail

getThumbnail(callback: AsyncCallback&lt;image.PixelMap&gt;): void

Obtains the thumbnail of this file asset. This API uses an asynchronous callback to return the result.

1268
**Required permissions**: ohos.permission.READ_IMAGEVIDEO or ohos.permission.READ_AUDIO
A
Annie_wang 已提交
1269 1270 1271 1272 1273 1274 1275

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

**Parameters**

| Name     | Type                                 | Mandatory  | Description              |
| -------- | ----------------------------------- | ---- | ---------------- |
1276
| callback | AsyncCallback&lt;[image.PixelMap](js-apis-image.md#pixelmap7)&gt; | Yes   | Callback invoked to return the pixel map of the thumbnail.|
A
Annie_wang 已提交
1277 1278 1279

**Example**

1280 1281 1282
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';

A
Annie_wang 已提交
1283
async function example() {
1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299
  console.info('getThumbnailDemo');
  let predicates = new dataSharePredicates.DataSharePredicates();
  let fetchOption = {
    fetchColumns: [],
    predicates: predicates
  };
  let fetchResult = await mgr.getPhotoAssets(fetchOption);
  const asset = await fetchResult.getFirstObject();
  console.info('asset displayName = ', asset.displayName);
  asset.getThumbnail((err, pixelMap) => {
    if (err == undefined) {
      console.info('getThumbnail successful ' + pixelMap);
    } else {
      console.info('getThumbnail fail', err);
    }
  });
A
Annie_wang 已提交
1300 1301 1302 1303 1304
}
```

### getThumbnail

1305
getThumbnail(size: image.Size, callback: AsyncCallback&lt;image.PixelMap&gt;): void
A
Annie_wang 已提交
1306 1307 1308

Obtains the file thumbnail of the given size. This API uses an asynchronous callback to return the result.

1309
**Required permissions**: ohos.permission.READ_IMAGEVIDEO or ohos.permission.READ_AUDIO
A
Annie_wang 已提交
1310 1311 1312 1313 1314 1315 1316

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

**Parameters**

| Name     | Type                                 | Mandatory  | Description              |
| -------- | ----------------------------------- | ---- | ---------------- |
1317 1318
| size     | [image.Size](js-apis-image.md#size) | Yes   | Size of the thumbnail to obtain.           |
| callback | AsyncCallback&lt;[image.PixelMap](js-apis-image.md#pixelmap7)&gt; | Yes   | Callback invoked to return the pixel map of the thumbnail.|
A
Annie_wang 已提交
1319 1320 1321

**Example**

1322 1323 1324
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';

A
Annie_wang 已提交
1325
async function example() {
1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342
  console.info('getThumbnailDemo');
  let predicates = new dataSharePredicates.DataSharePredicates();
  let fetchOption = {
    fetchColumns: [],
    predicates: predicates
  };
  let size = { width: 720, height: 720 };
  let fetchResult = await mgr.getPhotoAssets(fetchOption);
  const asset = await fetchResult.getFirstObject();
  console.info('asset displayName = ', asset.displayName);
  asset.getThumbnail(size, (err, pixelMap) => {
    if (err == undefined) {
      console.info('getThumbnail successful ' + pixelMap);
    } else {
      console.info('getThumbnail fail', err);
    }
  });
A
Annie_wang 已提交
1343 1344 1345 1346 1347
}
```

### getThumbnail

1348
getThumbnail(size?: image.Size): Promise&lt;image.PixelMap&gt;
A
Annie_wang 已提交
1349

1350
Obtains the file thumbnail of the given size. This API uses a promise to return the result.
A
Annie_wang 已提交
1351

1352
**Required permissions**: ohos.permission.READ_IMAGEVIDEO or ohos.permission.READ_AUDIO
A
Annie_wang 已提交
1353 1354 1355 1356 1357 1358 1359

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

**Parameters**

| Name | Type            | Mandatory  | Description   |
| ---- | -------------- | ---- | ----- |
1360
| size | [image.Size](js-apis-image.md#size) | No   | Size of the thumbnail to obtain.|
A
Annie_wang 已提交
1361 1362 1363 1364 1365

**Return value**

| Type                           | Description                   |
| ----------------------------- | --------------------- |
1366
| Promise&lt;[image.PixelMap](js-apis-image.md#pixelmap7)&gt; | Promise used to return the pixel map of the thumbnail.|
A
Annie_wang 已提交
1367 1368 1369

**Example**

1370 1371 1372
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';

A
Annie_wang 已提交
1373
async function example() {
1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388
  console.info('getThumbnailDemo');
  let predicates = new dataSharePredicates.DataSharePredicates();
  let fetchOption = {
    fetchColumns: [],
    predicates: predicates
  };
  let size = { width: 720, height: 720 };
  let fetchResult = await mgr.getPhotoAssets(fetchOption);
  const asset = await fetchResult.getFirstObject();
  console.info('asset displayName = ', asset.displayName);
  asset.getThumbnail(size).then((pixelMap) => {
    console.info('getThumbnail successful ' + pixelMap);
  }).catch((err) => {
    console.info('getThumbnail fail' + err);
  });
A
Annie_wang 已提交
1389 1390 1391 1392 1393 1394 1395 1396 1397
}
```

### favorite

favorite(isFavorite: boolean, callback: AsyncCallback&lt;void&gt;): void

Favorites or unfavorites this file asset. This API uses an asynchronous callback to return the result.

1398
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.WRITE_AUDIO
A
Annie_wang 已提交
1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

**Parameters**

| Name       | Type                       | Mandatory  | Description                                |
| ---------- | ------------------------- | ---- | ---------------------------------- |
| isFavorite | boolean                   | Yes   | Operation to perform. The value **true** means to favorite the file asset, and **false** means the opposite.|
| callback   | AsyncCallback&lt;void&gt; | Yes   | Callback that returns no value.                             |

**Example**

1411 1412 1413
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';

A
Annie_wang 已提交
1414
async function example() {
1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429
  console.info('favoriteDemo');
  let predicates = new dataSharePredicates.DataSharePredicates();
  let fetchOption = {
    fetchColumns: [],
    predicates: predicates
  };
  let fetchResult = await mgr.getPhotoAssets(fetchOption);
  const asset = await fetchResult.getFirstObject();
  asset.favorite(true, (err) => {
    if (err == undefined) {
      console.info("favorite successfully");
    } else {
      console.info("favorite failed with error:" + err);
    }
  });
A
Annie_wang 已提交
1430 1431 1432 1433 1434 1435 1436 1437 1438
}
```

### favorite

favorite(isFavorite: boolean): Promise&lt;void&gt;

Favorites or unfavorites this file asset. This API uses a promise to return the result.

1439
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.WRITE_AUDIO
A
Annie_wang 已提交
1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

**Parameters**

| Name       | Type     | Mandatory  | Description                                |
| ---------- | ------- | ---- | ---------------------------------- |
| isFavorite | boolean | Yes   | Operation to perform. The value **true** means to favorite the file asset, and **false** means the opposite.|

**Return value**

| Type                 | Description        |
| ------------------- | ---------- |
| Promise&lt;void&gt; | Promise that returns no value.|

**Example**

1457 1458
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';
A
Annie_wang 已提交
1459 1460

async function example() {
1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473
  console.info('favoriteDemo');
  let predicates = new dataSharePredicates.DataSharePredicates();
  let fetchOption = {
    fetchColumns: [],
    predicates: predicates
  };
  let fetchResult = await mgr.getPhotoAssets(fetchOption);
  const asset = await fetchResult.getFirstObject();
  asset.favorite(true).then(function () {
    console.info("favorite successfully");
  }).catch(function (err) {
    console.info("favorite failed with error:" + err);
  });
A
Annie_wang 已提交
1474 1475 1476
}
```

1477
## FetchResult
A
Annie_wang 已提交
1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496

Provides APIs to manage the file retrieval result.

### getCount

getCount(): number

Obtains the total number of files in the result set.

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

**Return value**

| Type    | Description      |
| ------ | -------- |
| number | Total number of files.|

**Example**

1497 1498 1499
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';

A
Annie_wang 已提交
1500
async function example() {
1501 1502 1503 1504 1505 1506 1507 1508 1509
  console.info('getCountDemo');
  let predicates = new dataSharePredicates.DataSharePredicates();
  let fetchOption = {
    fetchColumns: [],
    predicates: predicates
  };
  let fetchResult = await mgr.getPhotoAssets(fetchOption);
  const fetchCount = fetchResult.getCount();
  console.info('fetchCount = ', fetchCount);
A
Annie_wang 已提交
1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528
}
```

### isAfterLast

isAfterLast(): boolean

Checks whether the cursor is in the last row of the result set.

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

**Return value**

| Type     | Description                                |
| ------- | ---------------------------------- |
| boolean | Returns **true** if the cursor is in the last row of the result set; returns **false** otherwise.|

**Example**

1529 1530 1531
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';

A
Annie_wang 已提交
1532
async function example() {
1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546
  let predicates = new dataSharePredicates.DataSharePredicates();
  let fetchOption = {
    fetchColumns: [],
    predicates: predicates
  };
  let fetchResult = await mgr.getPhotoAssets(fetchOption);
  const fetchCount = fetchResult.getCount();
  console.info('count:' + fetchCount);
  let fileAsset = await fetchResult.getLastObject();
  if (!fetchResult.isAfterLast()) {
    console.info('fileAsset isAfterLast displayName = ', fileAsset.displayName);
  } else {
    console.info('fileAsset  not isAfterLast ');
  }
A
Annie_wang 已提交
1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559
}
```

### close

close(): void

Releases and invalidates this **FetchFileResult** instance. After this instance is released, the APIs in this instance cannot be invoked.

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

**Example**

1560 1561 1562
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';

A
Annie_wang 已提交
1563
async function example() {
1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576
  console.info('fetchResultCloseDemo');
  let predicates = new dataSharePredicates.DataSharePredicates();
  let fetchOption = {
    fetchColumns: [],
    predicates: predicates
  };
  try {
    let fetchResult = await mgr.getPhotoAssets(fetchOption);
    await fetchResult.close();
    console.info('close succeed.');
  } catch (err) {
    console.info('close fail. message = ' + err);
  }
A
Annie_wang 已提交
1577 1578 1579 1580 1581
}
```

### getFirstObject

1582
getFirstObject(callback: AsyncCallback&lt;T&gt;): void
A
Annie_wang 已提交
1583 1584 1585 1586 1587 1588 1589 1590 1591

Obtains the first file asset in the result set. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

**Parameters**

| Name  | Type                                         | Mandatory| Description                                       |
| -------- | --------------------------------------------- | ---- | ------------------------------------------- |
1592
| callback | AsyncCallback&lt;T&gt; | Yes  | Callback invoked to return the first file asset.|
A
Annie_wang 已提交
1593 1594 1595

**Example**

1596 1597 1598
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';

A
Annie_wang 已提交
1599
async function example() {
1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613
  console.info('getFirstObjectDemo');
  let predicates = new dataSharePredicates.DataSharePredicates();
  let fetchOption = {
    fetchColumns: [],
    predicates: predicates
  };
  let fetchResult = await mgr.getPhotoAssets(fetchOption);
  fetchResult.getFirstObject((err, fileAsset) => {
    if (fileAsset != undefined) {
      console.info('fileAsset displayName: ', fileAsset.displayName);
    } else {
      console.info("fileAsset failed with err:" + err);
    }
  });
A
Annie_wang 已提交
1614 1615 1616 1617 1618
}
```

### getFirstObject

1619
getFirstObject(): Promise&lt;T&gt;
A
Annie_wang 已提交
1620 1621 1622 1623 1624 1625 1626 1627 1628

Obtains the first file asset in the result set. This API uses a promise to return the result.

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

**Return value**

| Type                                   | Description                      |
| --------------------------------------- | -------------------------- |
1629
| Promise&lt;T&gt; | Promise used to return the first file asset.|
A
Annie_wang 已提交
1630 1631 1632

**Example**

1633 1634 1635
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';

A
Annie_wang 已提交
1636
async function example() {
1637 1638 1639 1640 1641 1642 1643 1644 1645
  console.info('getFirstObjectDemo');
  let predicates = new dataSharePredicates.DataSharePredicates();
  let fetchOption = {
    fetchColumns: [],
    predicates: predicates
  };
  let fetchResult = await mgr.getPhotoAssets(fetchOption);
  let fileAsset = await fetchResult.getFirstObject();
  console.info('fileAsset displayName: ', fileAsset.displayName);
A
Annie_wang 已提交
1646 1647 1648 1649 1650
}
```

### getNextObject

1651
 getNextObject(callback: AsyncCallback&lt;T&gt;): void
A
Annie_wang 已提交
1652 1653 1654 1655 1656 1657 1658 1659 1660

Obtains the next file asset in the result set. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

**Parameters**

| Name   | Type                                         | Mandatory| Description                                     |
| --------- | --------------------------------------------- | ---- | ----------------------------------------- |
1661
| callbacke | AsyncCallback&lt;T&gt; | Yes  | Callback invoked to return the next file asset.|
A
Annie_wang 已提交
1662 1663 1664

**Example**

1665 1666 1667
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';

A
Annie_wang 已提交
1668
async function example() {
1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685
  console.info('getNextObjectDemo');
  let predicates = new dataSharePredicates.DataSharePredicates();
  let fetchOption = {
    fetchColumns: [],
    predicates: predicates
  };
  let fetchResult = await mgr.getPhotoAssets(fetchOption);
  await fetchResult.getFirstObject();
  if (fetchResult.isAfterLast()) {
    fetchResult.getNextObject((err, fileAsset) => {
      if (fileAsset != undefined) {
        console.info('fileAsset displayName: ', fileAsset.displayName);
      } else {
        console.info("fileAsset failed with err:" + err);
      }
    });
  }
A
Annie_wang 已提交
1686 1687 1688 1689 1690
}
```

### getNextObject

1691
 getNextObject(): Promise&lt;T&gt;
A
Annie_wang 已提交
1692 1693 1694 1695 1696 1697 1698 1699 1700

Obtains the next file asset in the result set. This API uses a promise to return the result.

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

**Return value**

| Type                                   | Description             |
| --------------------------------------- | ----------------- |
1701
| Promise&lt;T&gt; | Promise used to return the next file asset obtained.|
A
Annie_wang 已提交
1702 1703 1704

**Example**

1705 1706 1707
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';

A
Annie_wang 已提交
1708
async function example() {
1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720
  console.info('getNextObjectDemo');
  let predicates = new dataSharePredicates.DataSharePredicates();
  let fetchOption = {
    fetchColumns: [],
    predicates: predicates
  };
  let fetchResult = await mgr.getPhotoAssets(fetchOption);
  await fetchResult.getFirstObject();
  if (fetchResult.isAfterLast()) {
    let fileAsset = await fetchResult.getNextObject();
    console.info('fileAsset displayName: ', fileAsset.displayName);
  }
A
Annie_wang 已提交
1721 1722 1723 1724 1725
}
```

### getLastObject

1726
getLastObject(callback: AsyncCallback&lt;T&gt;): void
A
Annie_wang 已提交
1727 1728 1729 1730 1731 1732 1733 1734 1735

Obtains the last file asset in the result set. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

**Parameters**

| Name  | Type                                         | Mandatory| Description                       |
| -------- | --------------------------------------------- | ---- | --------------------------- |
1736
| callback | AsyncCallback&lt;T&gt; | Yes  | Callback invoked to return the last file asset obtained.|
A
Annie_wang 已提交
1737 1738 1739

**Example**

1740 1741 1742
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';

A
Annie_wang 已提交
1743
async function example() {
1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757
  console.info('getLastObjectDemo');
  let predicates = new dataSharePredicates.DataSharePredicates();
  let fetchOption = {
    fetchColumns: [],
    predicates: predicates
  };
  let fetchResult = await mgr.getPhotoAssets(fetchOption);
  fetchResult.getLastObject((err, fileAsset) => {
    if (fileAsset != undefined) {
      console.info('fileAsset displayName: ', fileAsset.displayName);
    } else {
      console.info("fileAsset failed with err:" + err);
    }
  });
A
Annie_wang 已提交
1758 1759 1760 1761 1762
}
```

### getLastObject

1763
getLastObject(): Promise&lt;T&gt;
A
Annie_wang 已提交
1764 1765 1766 1767 1768 1769 1770 1771 1772

Obtains the last file asset in the result set. This API uses a promise to return the result.

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

**Return value**

| Type                                   | Description             |
| --------------------------------------- | ----------------- |
1773
| Promise&lt;T&gt; | Promise used to return the last file asset obtained.|
A
Annie_wang 已提交
1774 1775 1776

**Example**

1777 1778 1779
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';

A
Annie_wang 已提交
1780
async function example() {
1781 1782 1783 1784 1785 1786 1787 1788 1789
  console.info('getLastObjectDemo');
  let predicates = new dataSharePredicates.DataSharePredicates();
  let fetchOption = {
    fetchColumns: [],
    predicates: predicates
  };
  let fetchResult = await mgr.getPhotoAssets(fetchOption);
  let fileAsset = await fetchResult.getLastObject();
  console.info('fileAsset displayName: ', fileAsset.displayName);
A
Annie_wang 已提交
1790 1791 1792 1793 1794
}
```

### getPositionObject

1795
getPositionObject(index: number, callback: AsyncCallback&lt;T&gt;): void
A
Annie_wang 已提交
1796 1797 1798 1799 1800 1801 1802 1803 1804 1805

Obtains a file asset with the specified index in the result set. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

**Parameters**

| Name      | Type                                      | Mandatory  | Description                |
| -------- | ---------------------------------------- | ---- | ------------------ |
| index    | number                                   | Yes   | Index of the file asset to obtain. The value starts from **0**.    |
1806
| callback | AsyncCallback&lt;T&gt; | Yes   | Callback invoked to return the file asset obtained.|
A
Annie_wang 已提交
1807 1808 1809

**Example**

1810 1811 1812
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';

A
Annie_wang 已提交
1813
async function example() {
1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827
  console.info('getPositionObjectDemo');
  let predicates = new dataSharePredicates.DataSharePredicates();
  let fetchOption = {
    fetchColumns: [],
    predicates: predicates
  };
  let fetchResult = await mgr.getPhotoAssets(fetchOption);
  fetchResult.getPositionObject(0, (err, fileAsset) => {
    if (fileAsset != undefined) {
      console.info('fileAsset displayName: ', fileAsset.displayName);
    } else {
      console.info("fileAsset failed with err:" + err);
    }
  });
A
Annie_wang 已提交
1828 1829 1830 1831 1832
}
```

### getPositionObject

1833
getPositionObject(index: number): Promise&lt;T&gt;
A
Annie_wang 已提交
1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848

Obtains a file asset with the specified index in the result set. This API uses a promise to return the result.

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

**Parameters**

| Name   | Type    | Mandatory  | Description            |
| ----- | ------ | ---- | -------------- |
| index | number | Yes   | Index of the file asset to obtain. The value starts from **0**.|

**Return value**

| Type                                   | Description             |
| --------------------------------------- | ----------------- |
1849
| Promise&lt;T&gt; | Promise used to return the file asset obtained.|
A
Annie_wang 已提交
1850 1851 1852

**Example**

1853 1854 1855
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';

A
Annie_wang 已提交
1856
async function example() {
1857 1858 1859 1860 1861 1862 1863 1864 1865
  console.info('getPositionObjectDemo');
  let predicates = new dataSharePredicates.DataSharePredicates();
  let fetchOption = {
    fetchColumns: [],
    predicates: predicates
  };
  let fetchResult = await mgr.getPhotoAssets(fetchOption);
  let fileAsset = await fetchResult.getPositionObject(0);
  console.info('fileAsset displayName: ', fileAsset.displayName);
A
Annie_wang 已提交
1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884
}
```

## Album

Provides APIs to manage albums.

### Attributes

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

| Name          | Type   | Readable  | Writable  | Description     |
| ------------ | ------ | ---- | ---- | ------- |
| albumName | string | Yes   | Yes   | Album name.   |
| albumUri | string | Yes   | No   | Album URI.  |
| dateModified | number | Yes   | No   | Date when the album was last modified.   |
| count | number | Yes   | No   | Number of files in the album.|
| coverUri | string | Yes   | No   | URI of the cover file of the album.

1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971
### getPhotoAssets

getPhotoAssets(options: FetchOptions, callback: AsyncCallback&lt;FetchResult&lt;FileAsset&gt;&gt;): void;

Obtains image and video assets. This API uses an asynchronous callback to return the result.

**Required permissions**: ohos.permission.READ_IMAGEVIDEO

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

**Parameters**

| Name  | Type                     | Mandatory| Description      |
| -------- | ------------------------- | ---- | ---------- |
| options | [FetchOptions](#fetchoptions) | Yes  | Options for fetching the image and video assets.|
| callback | AsyncCallback&lt;[FetchResult](#fetchresult)&lt;[FileAsset](#fileasset)&gt;&gt; | Yes  | Callback invoked to return the image and video assets obtained.|

**Example**

```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';

async function example() {
  console.info('albumGetFileAssetsDemoCallback');

  let predicates = new dataSharePredicates.DataSharePredicates();
  let albumFetchOptions = {
    predicates: predicates
  };
  let fetchOption = {
    fetchColumns: [],
    predicates: predicates
  };
  const albumList = await mgr.getPhotoAlbums(albumFetchOptions);
  const album = await albumList.getFirstObject();
  album.getPhotoAssets(fetchOption, (err, albumFetchResult) => {
    if (albumFetchResult != undefined) {
      console.info("album getPhotoAssets successfully, getCount:" + albumFetchResult.getCount());
    } else {
      console.info("album getPhotoAssets failed with error:" + err);
    }
  });
}
```
### getPhotoAssets

getPhotoAssets(options: FetchOptions): Promise&lt;FetchResult&lt;FileAsset&gt;&gt;;

Obtains image and video assets. This API uses a promise to return the result.

**Required permissions**: ohos.permission.READ_IMAGEVIDEO

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

**Parameters**

| Name  | Type                     | Mandatory| Description      |
| -------- | ------------------------- | ---- | ---------- |
| options | [FetchOptions](#fetchoptions) | Yes  | Options for fetching the image and video assets.|
| Promise | [FetchResult](#fetchresult)&lt;[FileAsset](#fileasset)&gt; | Yes  | Promise used to return the image and video assets obtained.|

**Example**

```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';

async function example() {
  console.info('albumGetFileAssetsDemoPromise');

  let predicates = new dataSharePredicates.DataSharePredicates();
  let albumFetchOptions = {
    predicates: predicates
  };
  let fetchOption = {
    fetchColumns: [],
    predicates: predicates
  };
  const albumList = await mgr.getPhotoAlbums(albumFetchOptions);
  const album = await albumList.getFirstObject();
  album.getPhotoAssets(fetchOption).then((albumFetchResult) => {
    console.info("album getFileAssets successfully, getCount:" + albumFetchResult.getCount());
  }).catch((err) => {
    console.info("album getFileAssets failed with error:" + err);
  });
}
```

A
Annie_wang 已提交
1972 1973 1974 1975 1976 1977
### commitModify

commitModify(callback: AsyncCallback&lt;void&gt;): void;

Commits the modification on the album attributes to the database. This API uses an asynchronous callback to return the result.

1978
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
A
Annie_wang 已提交
1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

**Parameters**

| Name  | Type                     | Mandatory| Description      |
| -------- | ------------------------- | ---- | ---------- |
| callback | AsyncCallback&lt;void&gt; | Yes  | Callback that returns no value.|

**Example**

```ts
1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008
import dataSharePredicates from '@ohos.data.dataSharePredicates';

async function example() {
  console.info('albumCommitModifyDemo');
  let predicates = new dataSharePredicates.DataSharePredicates();
  let albumFetchOptions = {
    predicates: predicates
  };
  const albumList = await mgr.getPhotoAlbums(albumFetchOptions);
  const album = await albumList.getFirstObject();
  album.albumName = 'hello';
  album.commitModify((err) => {
    if (err != undefined) {
      console.info("commitModify failed with error:" + err);
    } else {
      console.info("commitModify successfully");
    }
  });
A
Annie_wang 已提交
2009 2010 2011 2012 2013 2014 2015 2016 2017
}
```

### commitModify

commitModify(): Promise&lt;void&gt;;

Commits the modification on the album attributes to the database. This API uses a promise to return the result.

2018
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
A
Annie_wang 已提交
2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

**Return value**

| Type                 | Description          |
| ------------------- | ------------ |
| Promise&lt;void&gt; | Promise that returns no value.|

**Example**

```ts
2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050
import dataSharePredicates from '@ohos.data.dataSharePredicates';

async function example() {
  console.info('albumCommitModifyDemo');
  let predicates = new dataSharePredicates.DataSharePredicates();
  let albumFetchOptions = {
    predicates: predicates
  };
  try {
    var albumList = await mgr.getPhotoAlbums(albumFetchOptions);
  } catch (err) {
    console.info('getPhotoAlbums failed. message = ', err);
  }
  const album = await albumList.getFirstObject();
  album.albumName = 'hello';
  album.commitModify().then(() => {
    console.info("commitModify successfully");
  }).catch((err) => {
    console.info("commitModify failed with error:" + err);
  });
A
Annie_wang 已提交
2051 2052 2053
}
```

2054
## PrivateAlbum
A
Annie_wang 已提交
2055

2056
Provides APIs for managing the system albums.
A
Annie_wang 已提交
2057

2058
### Attributes
A
Annie_wang 已提交
2059

2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076
**System capability**: SystemCapability.FileManagement.UserFileManager.Core

| Name          | Type   | Readable  | Writable  | Description     |
| ------------ | ------ | ---- | ---- | ------- |
| albumName | string | Yes   | Yes   | Album name.   |
| albumUri | string | Yes   | No   | Album URI.  |
| dateModified | number | Yes   | No   | Date when the album was last modified.   |
| count | number | Yes   | No   | Number of files in the album.|
| coverUri | string | Yes   | No   | URI of the cover file of the album.

### getPhotoAssets

getPhotoAssets(options: FetchOptions, callback: AsyncCallback&lt;FetchResult&lt;FileAsset&gt;&gt;): void;

Obtains image and video assets from a system album. This API uses an asynchronous callback to return the result.

**Required permissions**: ohos.permission.READ_IMAGEVIDEO
A
Annie_wang 已提交
2077 2078 2079 2080 2081

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

**Parameters**

2082 2083 2084 2085
| Name  | Type                     | Mandatory| Description      |
| -------- | ------------------------- | ---- | ---------- |
| options | [FetchOptions](#fetchoptions) | Yes  | Options for fetching the image and video assets.|
| callback | AsyncCallback&lt;[FetchResult](#fetchresult)&lt;[FileAsset](#fileasset)&gt;&gt; | Yes  | Callback invoked to return the image and video assets obtained.|
A
Annie_wang 已提交
2086 2087 2088 2089

**Example**

```ts
2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108
import dataSharePredicates from '@ohos.data.dataSharePredicates';

async function example() {
  console.info('privateAlbumGetFileAssetsDemoCallback');
  let albumList = await mgr.getPrivateAlbum(userFileManager.PrivateAlbumType.TYPE_TRASH);
  let predicates = new dataSharePredicates.DataSharePredicates();
  let fetchOption = {
    fetchColumns: [],
    predicates: predicates
  };
  const trashAlbum = await albumList.getFirstObject();
  trashAlbum.getPhotoAssets(fetchOption, (err, fetchResult) => {
    if (fetchResult != undefined) {
      let count = fetchResult.getCount();
      console.info('fetchResult.count = ', count);
    } else {
      console.info('getFileAssets failed, message = ', err);
    }
  });
A
Annie_wang 已提交
2109 2110
}

2111 2112
```
### getPhotoAssets
A
Annie_wang 已提交
2113

2114
getPhotoAssets(options: FetchOptions): Promise&lt;FetchResult&lt;FileAsset&gt;&gt;;
A
Annie_wang 已提交
2115

2116
Obtains image and video assets from a system album. This API uses a promise to return the result.
A
Annie_wang 已提交
2117

2118
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
A
Annie_wang 已提交
2119 2120 2121 2122 2123

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

**Parameters**

2124 2125 2126 2127 2128 2129 2130 2131 2132
| Name  | Type                     | Mandatory| Description      |
| -------- | ------------------------- | ---- | ---------- |
| options | [FetchOptions](#fetchoptions) | Yes  | Options for fetching the image and video assets.|

**Return value**

| Type                                   | Description             |
| --------------------------------------- | ----------------- |
| Promise:[FetchResult](#fetchresult)&lt;[FileAsset](#fileasset)&gt;| Promise used to return the image and video assets obtained.|
A
Annie_wang 已提交
2133 2134 2135 2136

**Example**

```ts
2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151
import dataSharePredicates from '@ohos.data.dataSharePredicates';

async function example() {
  console.info('privateAlbumGetFileAssetsDemoPromise');
  let albumList = await mgr.getPrivateAlbum(userFileManager.PrivateAlbumType.TYPE_TRASH);
  let predicates = new dataSharePredicates.DataSharePredicates();
  let fetchOption = {
    fetchColumns: [],
    predicates: predicates
  };
  const trashAlbum = await albumList.getFirstObject();
  let fetchResult = await trashAlbum.getPhotoAssets(fetchOption);
  let count = fetchResult.getCount();
  console.info('fetchResult.count = ', count);
}
A
Annie_wang 已提交
2152
```
2153 2154 2155
### delete

delete(uri: string, callback: AsyncCallback&lt;void&gt;): void;
A
Annie_wang 已提交
2156

2157 2158 2159 2160 2161
Deletes files from a system album.

**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.READ_AUDIO, and ohos.permission.WRITE_AUDIO

**System capability**: SystemCapability.FileManagement.UserFileManager.Core
A
Annie_wang 已提交
2162

2163
**Parameters**
A
Annie_wang 已提交
2164

2165 2166 2167 2168
| Name  | Type                     | Mandatory| Description      |
| -------- | ------------------------- | ---- | ---------- |
| uri | string | Yes  | Album URI.|
| callback | AsyncCallback&lt;void&gt; | Yes  | Callback that returns no value.|
A
Annie_wang 已提交
2169

2170
**Example**
A
Annie_wang 已提交
2171

2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202
```ts
import dataSharePredicates from '@ohos.data.dataSharePredicates';

async function example() {
  console.info('privateAlbumDeleteCallback');
  let albumList = await mgr.getPrivateAlbum(userFileManager.PrivateAlbumType.TYPE_TRASH);
  let predicates = new dataSharePredicates.DataSharePredicates();
  let fetchOption = {
    fetchColumns: [],
    predicates: predicates
  };
  const trashAlbum = await albumList.getFirstObject();
  let fetchResult = await trashAlbum.getPhotoAssets(fetchOption);
  const fileAsset = await fetchResult.getFirstObject();
  let deleteFileUri = fileAsset.uri;
  trashAlbum.delete(deleteFileUri, (err) => {
    if (err != undefined) {
      console.info('trashAlbum.delete failed, message = ', err);
    } else {
      console.info('trashAlbum.delete successfully');
    }
  });
}
```
### delete

delete(uri: string): Promise&lt;void&gt;;

Deletes files from a system album.

**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.READ_AUDIO, and ohos.permission.WRITE_AUDIO
A
Annie_wang 已提交
2203 2204 2205 2206 2207

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

**Parameters**

2208 2209 2210
| Name  | Type                     | Mandatory| Description      |
| -------- | ------------------------- | ---- | ---------- |
| uri | string | Yes  | Album URI.|
A
Annie_wang 已提交
2211 2212 2213

**Return value**

2214 2215 2216
| Type                                   | Description             |
| --------------------------------------- | ----------------- |
| Promise&lt;void&gt;| Promise that returns no value.|
A
Annie_wang 已提交
2217 2218 2219 2220

**Example**

```ts
2221
import dataSharePredicates from '@ohos.data.dataSharePredicates';
A
Annie_wang 已提交
2222

2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241
async function example() {
  console.info('privateAlbumDeleteDemoPromise');
  let albumList = await mgr.getPrivateAlbum(userFileManager.PrivateAlbumType.TYPE_TRASH);
  let predicates = new dataSharePredicates.DataSharePredicates();
  let fetchOption = {
    fetchColumns: [],
    predicates: predicates
  };
  const trashAlbum = await albumList.getFirstObject();
  let fetchResult = await trashAlbum.getPhotoAssets(fetchOption);
  const fileAsset = await fetchResult.getFirstObject();
  let deleteFileUri = fileAsset.uri;
  trashAlbum.delete(deleteFileUri).then(() => {
    console.info('trashAlbum.delete successfully');
  }).catch((err) => {
    console.info('trashAlbum.delete failed, message = ', err);
  });
}   
```
A
Annie_wang 已提交
2242

2243
### recover
A
Annie_wang 已提交
2244

2245
recover(uri: string, callback: AsyncCallback&lt;void&gt;): void;
A
Annie_wang 已提交
2246

2247
Recovers files in a system album.
A
Annie_wang 已提交
2248

2249
**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.READ_AUDIO, and ohos.permission.WRITE_AUDIO
A
Annie_wang 已提交
2250 2251 2252 2253

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

**Parameters**
2254 2255 2256 2257 2258

| Name  | Type                     | Mandatory| Description      |
| -------- | ------------------------- | ---- | ---------- |
| uri | string | Yes  | Album URI.|
| callback | AsyncCallback&lt;void&gt; | Yes  | Callback that returns no value.|
A
Annie_wang 已提交
2259 2260 2261 2262

**Example**

```ts
2263
import dataSharePredicates from '@ohos.data.dataSharePredicates';
A
Annie_wang 已提交
2264

2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283
async function example() {
  console.info('privateAlbumRecoverDemoCallback');
  let albumList = await mgr.getPrivateAlbum(userFileManager.PrivateAlbumType.TYPE_TRASH);
  let predicates = new dataSharePredicates.DataSharePredicates();
  let fetchOption = {
    fetchColumns: [],
    predicates: predicates
  };
  const trashAlbum = await albumList.getFirstObject();
  let fetchResult = await trashAlbum.getPhotoAssets(fetchOption);
  const fileAsset = await fetchResult.getFirstObject();
  let recoverFileUri = fileAsset.uri;
  trashAlbum.recover(recoverFileUri, (err) => {
    if (err != undefined) {
      console.info('trashAlbum.recover failed, message = ', err);
    } else {
      console.info('trashAlbum.recover successfully');
    }
  });
A
Annie_wang 已提交
2284 2285
}
```
2286
### recover
A
Annie_wang 已提交
2287

2288
recover(uri: string): Promise&lt;void&gt;;
A
Annie_wang 已提交
2289

2290
Recovers files in a system album.
A
Annie_wang 已提交
2291

2292
**Required permissions**: ohos.permission.READ_IMAGEVIDEO, ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.READ_AUDIO, and ohos.permission.WRITE_AUDIO
A
Annie_wang 已提交
2293 2294 2295 2296 2297

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

**Parameters**

2298 2299 2300
| Name  | Type                     | Mandatory| Description      |
| -------- | ------------------------- | ---- | ---------- |
| uri | string | Yes  | Album URI.|
A
Annie_wang 已提交
2301 2302 2303

**Return value**

2304 2305 2306
| Type                                   | Description             |
| --------------------------------------- | ----------------- |
| Promise&lt;void&gt;| Promise that returns no value.|
A
Annie_wang 已提交
2307 2308 2309 2310

**Example**

```ts
2311
import dataSharePredicates from '@ohos.data.dataSharePredicates';
A
Annie_wang 已提交
2312

2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329
async function example() {
  console.info('privateAlbumRecoverDemoPromise');
  let albumList = await mgr.getPrivateAlbum(userFileManager.PrivateAlbumType.TYPE_TRASH);
  let predicates = new dataSharePredicates.DataSharePredicates();
  let fetchOption = {
    fetchColumns: [],
    predicates: predicates
  };
  const trashAlbum = await albumList.getFirstObject();
  let fetchResult = await trashAlbum.getPhotoAssets(fetchOption);
  const fileAsset = await fetchResult.getFirstObject();
  let recoverFileUri = fileAsset.uri;
  trashAlbum.recover(recoverFileUri).then(() => {
    console.info('trashAlbum.recover successfully');
  }).catch((err) => {
    console.info('trashAlbum.recover failed, message = ', err);
  });
A
Annie_wang 已提交
2330 2331 2332
}
```

2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359
## MemberType

Enumerates the member types.

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

| Name |  Type|  Readable |  Writable |  Description |
| ----- |  ---- |  ---- |  ---- |  ---- |
| number |  number | Yes| Yes| The member is a number.|
| string |  string | Yes| Yes| The member is a string.|
| boolean |  boolean | Yes| Yes| The member is a Boolean value.|

## ChangeEvent

Enumerates the type of changes to observe.

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

| Name |  Type|  Readable |  Writable |  Description|
| ----- |  ---- |  ---- |  ---- |  ---- |
| deviceChange |  string | Yes| Yes|  Device.|
| albumChange |  string | Yes| Yes|  Album.|
| imageChange |  string | Yes| Yes|  Image.|
| audioChange |  string | Yes| Yes|  Audio.|
| videoChange |  string | Yes| Yes|  Video.|
| remoteFileChange |  string | Yes| Yes|  Remote file.|

A
Annie_wang 已提交
2360 2361
## PeerInfo

2362
Defines information about a registered device.
A
Annie_wang 已提交
2363 2364 2365 2366 2367 2368 2369 2370 2371 2372

**System capability**: SystemCapability.FileManagement.UserFileManager.DistributedCore

| Name      | Type                      | Readable| Writable| Description            |
| ---------- | -------------------------- | ---- | ---- | ---------------- |
| deviceName | string                     | Yes  | No  | Name of the registered device.  |
| networkId  | string                     | Yes  | No  | Network ID of the registered device.|
| isOnline   | boolean                    | Yes  | No  | Whether the registered device is online.        |


2373 2374 2375
## FileType

Enumerates media file types.
A
Annie_wang 已提交
2376 2377 2378

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

2379 2380 2381 2382 2383
| Name |  Value|  Description|
| ----- |  ---- |  ---- |
| IMAGE |  1 |  Image.|
| VIDEO |  2 |  Video.|
| AUDIO |  3 |  Audio.|
A
Annie_wang 已提交
2384

2385
## PrivateAlbumType
A
Annie_wang 已提交
2386

2387
Enumerates the system album types.
A
Annie_wang 已提交
2388 2389 2390

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

2391 2392 2393 2394 2395 2396
| Name   |  Value|   Description  |
| -----   |  ----  |   ----  |
| TYPE_FAVORITE |  0 |  Favorites.|
| TYPE_TRASH |  1 |  Recycle bin.|


A
Annie_wang 已提交
2397 2398 2399 2400 2401 2402 2403

## AudioKey

Defines the key information about an audio file.

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

2404
| Name         |   Value             | Description                                                      |
A
Annie_wang 已提交
2405
| ------------- | ------------------- | ---------------------------------------------------------- |
2406
| URI           | uri                 | File URI.                                                  |
A
Annie_wang 已提交
2407 2408 2409 2410 2411 2412 2413
| DISPLAY_NAME  | display_name        | File name displayed.                                                  |
| DATE_ADDED    | date_added          | Date when the file was added. The value is the number of seconds elapsed since the Epoch time.            |
| DATE_MODIFIED | date_modified       | Date when the file was last modified. The value is the number of seconds elapsed since the Epoch time.            |
| TITLE         | title               | Title in the file.                                                  |
| ARTIST        | artist              | Author of the file.                                                  |
| AUDIOALBUM    | audio_album         | Audio album.                                                  |
| DURATION      | duration            | Duration, in ms.                                   |
2414
| FAVORITE      | favorite            | Whether the file is added to favorites.                                                  |
A
Annie_wang 已提交
2415 2416 2417 2418 2419 2420 2421

## ImageVideoKey

Defines the key information about an image or video file.

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

2422
| Name         | Value             | Description                                                      |
A
Annie_wang 已提交
2423 2424
| ------------- | ------------------- | ---------------------------------------------------------- |
| URI           | uri                 | File URI.                                                  |
2425
| FILE_TYPE     | file_type           | Type of the file.                                             |
A
Annie_wang 已提交
2426 2427 2428
| DISPLAY_NAME  | display_name        | File name displayed.                                                  |
| DATE_ADDED    | date_added          | Date when the file was added. The value is the number of seconds elapsed since the Epoch time.            |
| DATE_MODIFIED | date_modified       | Date when the file was last modified. The value is the number of seconds elapsed since the Epoch time.            |
2429
| TITLE         | title               | Title in the file.                                                  |
A
Annie_wang 已提交
2430 2431 2432 2433
| DURATION      | duration            | Duration, in ms.                                   |
| WIDTH         | width               | Image width, in pixels.                                   |
| HEIGHT        | height              | Image height, in pixels.                                     |
| DATE_TAKEN    | date_taken          | Date when the file (photo) was taken. The value is the number of seconds elapsed since the Epoch time.               |
2434 2435
| ORIENTATION   | orientation         | Orientation of the image file.                                            |
| FAVORITE      | favorite            | Whether the file is added to favorites.                                                   |
A
Annie_wang 已提交
2436 2437 2438 2439 2440 2441 2442

## AlbumKey

Defines the key album information.

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

2443
| Name         | Value             | Description                                                      |
A
Annie_wang 已提交
2444 2445
| ------------- | ------------------- | ---------------------------------------------------------- |
| URI           | uri                 | Album URI.                                                  |
2446 2447 2448 2449
| FILE_TYPE     | file_type           | Type of the file.                                             |
| ALBUM_NAME    | album_name          | Name of the album.                                                  |
| DATE_ADDED    | date_added          | Date when the file was added. The value is the number of seconds elapsed since the Epoch time.            |
| DATE_MODIFIED | date_modified       | Date when the file was last modified. The value is the number of seconds elapsed since the Epoch time.            |
A
Annie_wang 已提交
2450 2451


2452
## FetchOptions
A
Annie_wang 已提交
2453 2454 2455 2456 2457

Defines the options for fetching media files.

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

2458 2459 2460 2461
| Name                  | Type               | Readable| Writable| Description                                             |
| ---------------------- | ------------------- | ---- |---- | ------------------------------------------------ |
| 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"**.|
| predicates           | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md) | Yes  | Yes  | Predicates that specify the fetch criteria.|
A
Annie_wang 已提交
2462

2463
## AlbumFetchOptions
A
Annie_wang 已提交
2464

2465
Defines the options for fetching an album.
A
Annie_wang 已提交
2466 2467 2468

**System capability**: SystemCapability.FileManagement.UserFileManager.Core

2469 2470 2471
| Name                  | Type               | Readable| Writable| Description                                             |
| ---------------------- | ------------------- | ---- |---- | ------------------------------------------------ |
| predicates           | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md) | Yes  | Yes  | Predicates that specify the fetch criteria.|