js-apis-medialibrary.md 110.4 KB
Newer Older
G
gloria 已提交
1
# @ohos.multimedia.medialibrary (Media Library Management)
W
wusongqing 已提交
2

W
wusongqing 已提交
3
> **NOTE**
G
Gloria 已提交
4
>
G
Gloria 已提交
5
> - The APIs of this module are supported since API version 6. Updates will be marked with a superscript to indicate their earliest API version.
A
Annie_wang 已提交
6
> - The APIs of this module are deprecated since API version 9. For details about the substitute APIs, see the API description.
W
wusongqing 已提交
7 8

## Modules to Import
A
Annie_wang 已提交
9

10
```js
W
wusongqing 已提交
11
import mediaLibrary from '@ohos.multimedia.mediaLibrary';
W
wusongqing 已提交
12 13
```

W
wusongqing 已提交
14
## mediaLibrary.getMediaLibrary<sup>8+</sup>
W
wusongqing 已提交
15 16 17

getMediaLibrary(context: Context): MediaLibrary

W
wusongqing 已提交
18
Obtains a **MediaLibrary** instance, which is used to access and modify personal media data such as audios, videos, images, and documents.
W
wusongqing 已提交
19

20 21
This API can be used only in the stage model.

A
Annie_wang 已提交
22 23 24
> **NOTE**
> This API is deprecated since API Version 9. Use [getPhotoAccessHelper](js-apis-photoAccessHelper.md#photoaccesshelpergetphotoaccesshelper) instead.

W
wusongqing 已提交
25 26 27 28
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
29 30 31
| Name | Type   | Mandatory| Description                      |
| ------- | ------- | ---- | -------------------------- |
| context | Context | Yes  | Context of the ability.|
W
wusongqing 已提交
32 33 34

**Return value**

W
wusongqing 已提交
35 36
| Type                           | Description   |
| ----------------------------- | :---- |
A
Annie_wang 已提交
37
| [MediaLibrary](#medialibrary) | **MediaLibrary** instance obtained.|
W
wusongqing 已提交
38

W
wusongqing 已提交
39 40
**Example (from API version 9)**

41
```ts
G
Gloria 已提交
42
// Obtain a MediaLibrary instance. The instance obtained here is used in later.
43 44
const context = getContext(this);
let media = mediaLibrary.getMediaLibrary(context);
W
wusongqing 已提交
45 46 47
```

**Example (API version 8)**
W
wusongqing 已提交
48

49
```js
W
wusongqing 已提交
50 51
import featureAbility from '@ohos.ability.featureAbility';

52 53
let context = featureAbility.getContext();
let media = mediaLibrary.getMediaLibrary(context);
W
wusongqing 已提交
54
```
55

W
wusongqing 已提交
56 57 58 59 60 61
## mediaLibrary.getMediaLibrary

getMediaLibrary(): MediaLibrary

Obtains a **MediaLibrary** instance, which is used to access and modify personal media data such as audios, videos, images, and documents.

62 63
This API can be used only in the FA model.

A
Annie_wang 已提交
64 65 66
> **NOTE**
> This API is deprecated since API Version 9. There is no substitute API.

W
wusongqing 已提交
67 68 69 70 71 72
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Return value**

| Type                         | Description      |
| ----------------------------- | :--------- |
A
Annie_wang 已提交
73
| [MediaLibrary](#medialibrary) | **MediaLibrary** instance obtained.|
W
wusongqing 已提交
74 75 76 77

**Example**

```js
78
let media = mediaLibrary.getMediaLibrary();
W
wusongqing 已提交
79 80
```

W
wusongqing 已提交
81 82
## MediaLibrary

W
wusongqing 已提交
83
### getFileAssets<sup>7+</sup>
W
wusongqing 已提交
84 85 86 87 88

getFileAssets(options: MediaFetchOptions, callback: AsyncCallback&lt;FetchFileResult&gt;): void 

Obtains file assets (also called files). This API uses an asynchronous callback to return the result.

A
Annie_wang 已提交
89
> **NOTE**
A
Annie_wang 已提交
90 91 92
>
> - This API is deprecated since API Version 9. Use [getAssets](js-apis-photoAccessHelper.md#getassets) instead.
> - From API version 10, the albums represented by physical directories are replaced by logical albums, which allows multiple files in an album and presence of a file in multiple albums. This design, however, makes **parent**, **albumId**, **albumUri**, and **albumName** incompatible. They cannot be used as parameters of **MediaFetchOptions** in **getFileAssets()**. For details, see [changelogs-mediaLibrary.md](../../../release-notes/changelogs/OpenHarmony_4.0.8.2/changelogs-mediaLibrary.md).
A
Annie_wang 已提交
93

W
wusongqing 已提交
94 95 96 97 98 99
**Required permissions**: ohos.permission.READ_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
100 101 102
| Name  | Type                                               | Mandatory| Description                             |
| -------- | --------------------------------------------------- | ---- | --------------------------------- |
| options  | [MediaFetchOptions](#mediafetchoptions7)            | Yes  | Options for fetching the files.                     |
A
Annie_wang 已提交
103
| callback | AsyncCallback<[FetchFileResult](#fetchfileresult7)> | Yes  | Callback invoked to return the file retrieval result set.|
W
wusongqing 已提交
104 105 106

**Example**

107
```js
G
Gloria 已提交
108
async function example() {
A
Annie_wang 已提交
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  // Create options for fetching the files of the image type.
  let imagesFetchOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
  };
  // Obtain the files in asynchronous callback mode.
  media.getFileAssets(imagesFetchOp, async (error, fetchFileResult) => {
    // Check whether the result set of the obtained files is undefined. If yes, the API call fails.
    if (fetchFileResult == undefined) {
      console.error('get fetchFileResult failed with error: ' + error);
      return;
    }
    // Obtain the total number of files in the result set.
    const count = fetchFileResult.getCount();
    // Check whether the number is less than 0. If yes, the API call fails.
    if (count < 0) {
      console.error('get count from fetchFileResult failed, count: ' + count);
      return;
    }
    // Check whether the number is 0. If yes, the API call is successful, but the result set is empty. Check whether the options for fetching the files are correctly set and whether the corresponding files exist on the device.
    if (count == 0) {
      console.info('The count of fetchFileResult is zero');
      return;
    }
    console.info('Get fetchFileResult successfully, count: ' + count);
    // Obtain the first file in the result set in asynchronous callback mode. If there are a large number of files, use getAllObject() instead.
    fetchFileResult.getFirstObject(async (error, fileAsset) => {
      // Check whether the first file is undefined. If yes, the API call fails.
      if (fileAsset == undefined) {
        console.error('get first object failed with error: ' + error);
        return;
      }
      console.info('fileAsset.displayName ' + '0 : ' + fileAsset.displayName);
      // Call getNextObject to obtain the next file until the last one.
      for (let i = 1; i < count; i++) {
        let fileAsset = await fetchFileResult.getNextObject();
        console.info('fileAsset.displayName ' + i + ': ' + fileAsset.displayName);
      }
      // Release the FetchFileResult instance and invalidate it. Other APIs can no longer be called.
      fetchFileResult.close();
151
    });
A
Annie_wang 已提交
152
  });
G
Gloria 已提交
153
}
W
wusongqing 已提交
154
```
G
Gloria 已提交
155

W
wusongqing 已提交
156
### getFileAssets<sup>7+</sup>
W
wusongqing 已提交
157 158 159 160 161

getFileAssets(options: MediaFetchOptions): Promise&lt;FetchFileResult&gt;

Obtains file assets. This API uses a promise to return the result.

A
Annie_wang 已提交
162
> **NOTE**
A
Annie_wang 已提交
163 164 165
>
> - This API is deprecated since API Version 9. Use [getAssets](js-apis-photoAccessHelper.md#getassets-1) instead.
> - From API version 10, the albums represented by physical directories are replaced by logical albums, which allows multiple files in an album and presence of a file in multiple albums. This design, however, makes **parent**, **albumId**, **albumUri**, and **albumName** incompatible. They cannot be used as parameters of **MediaFetchOptions** in **getFileAssets()**. For details, see [changelogs-mediaLibrary.md](../../../release-notes/changelogs/OpenHarmony_4.0.8.2/changelogs-mediaLibrary.md).
A
Annie_wang 已提交
166

W
wusongqing 已提交
167 168 169 170 171 172
**Required permissions**: ohos.permission.READ_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
173 174 175
| Name | Type                                    | Mandatory| Description        |
| ------- | ---------------------------------------- | ---- | ------------ |
| options | [MediaFetchOptions](#mediafetchoptions7) | Yes  | Options for fetching the files.|
W
wusongqing 已提交
176 177 178

**Return value**

W
wusongqing 已提交
179 180
| Type                                | Description          |
| ------------------------------------ | -------------- |
A
Annie_wang 已提交
181
| Promise&lt;[FetchFileResult](#fetchfileresult7)&gt; | Promise used to return the file retrieval result set.|
W
wusongqing 已提交
182 183 184

**Example**

185
```js
G
Gloria 已提交
186
async function example() {
A
Annie_wang 已提交
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  // Create options for fetching the files of the image type.
  let imagesFetchOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
  };
  // Obtain the files in promise mode.
  media.getFileAssets(imagesFetchOp).then(async (fetchFileResult) => {
    // Obtain the total number of files in the result set.
    const count = fetchFileResult.getCount();
    // Check whether the number is less than 0. If yes, the API call fails.
    if (count < 0) {
      console.error('get count from fetchFileResult failed, count: ' + count);
      return;
    }
    // Check whether the number is 0. If yes, the API call is successful, but the result set is empty. Check whether the options for fetching the files are correctly set and whether the corresponding files exist on the device.
    if (count == 0) {
      console.info('The count of fetchFileResult is zero');
      return;
    }
    console.info('Get fetchFileResult successfully, count: ' + count);
    // Obtain the first file in the result set in promise mode. If there are a large number of files, use getAllObject instead.
    fetchFileResult.getFirstObject().then(async (fileAsset) => {
      console.info('fileAsset.displayName ' + '0 : ' + fileAsset.displayName);
      // Call getNextObject to obtain the next file until the last one.
      for (let i = 1; i < count; i++) {
        let fileAsset = await fetchFileResult.getNextObject();
        console.info('fileAsset.displayName ' + i + ': ' + fileAsset.displayName);
      }
      // Release the FetchFileResult instance and invalidate it. Other APIs can no longer be called.
      fetchFileResult.close();
G
Gloria 已提交
219
    }).catch((error) => {
A
Annie_wang 已提交
220 221
      // Calling getFirstObject fails.
      console.error('get first object failed with error: ' + error);
222
    });
A
Annie_wang 已提交
223 224 225 226
  }).catch((error) => {
    // Calling getFileAssets fails.
    console.error('get file assets failed with error: ' + error);
  });
G
Gloria 已提交
227
}
W
wusongqing 已提交
228 229 230 231
```

### on<sup>8+</sup>

G
gloria 已提交
232
on(type: 'deviceChange'&#124;'albumChange'&#124;'imageChange'&#124;'audioChange'&#124;'videoChange'&#124;'fileChange'&#124;'remoteFileChange', callback: Callback&lt;void&gt;): void
W
wusongqing 已提交
233

A
Annie_wang 已提交
234
Subscribes to the media library changes. This API uses a callback to return the result.
W
wusongqing 已提交
235

A
Annie_wang 已提交
236 237 238
> **NOTE**
> This API is deprecated since API Version 9. Use [registerChange](js-apis-photoAccessHelper.md#registerchange) instead.

W
wusongqing 已提交
239 240 241 242
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
243 244
| Name     | Type                  | Mandatory  | Description                                      |
| -------- | -------------------- | ---- | ---------------------------------------- |
A
Annie_wang 已提交
245 246
| type     | 'deviceChange'&#124;<br>'albumChange'&#124;<br>'imageChange'&#124;<br>'audioChange'&#124;<br>'videoChange'&#124;<br>'fileChange'&#124;<br>'remoteFileChange'               | Yes   | Type of the event to subscribe to.<br>'deviceChange': registered device change<br>'albumChange': album change<br>'imageChange': image file change<br>'audioChange': audio file change<br>'videoChange': video file change<br>'fileChange': file change<br>'remoteFileChange': file change on the registered device|
| callback | Callback&lt;void&gt; | Yes   | Callback that returns no value.                                   |
W
wusongqing 已提交
247 248 249

**Example**

250
```js
W
wusongqing 已提交
251
media.on('imageChange', () => {
A
Annie_wang 已提交
252 253
  // image file had changed, do something.
});
W
wusongqing 已提交
254
```
A
Annie_wang 已提交
255

W
wusongqing 已提交
256 257
### off<sup>8+</sup>

G
gloria 已提交
258
off(type: 'deviceChange'&#124;'albumChange'&#124;'imageChange'&#124;'audioChange'&#124;'videoChange'&#124;'fileChange'&#124;'remoteFileChange', callback?: Callback&lt;void&gt;): void
W
wusongqing 已提交
259

A
Annie_wang 已提交
260
Unsubscribes from the media library changes. This API uses a callback to return the result.
W
wusongqing 已提交
261

A
Annie_wang 已提交
262 263 264
> **NOTE**
> This API is deprecated since API Version 9. Use [unRegisterChange](js-apis-photoAccessHelper.md#unregisterchange) instead.

W
wusongqing 已提交
265 266 267 268
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
269 270
| Name     | Type                  | Mandatory  | Description                                      |
| -------- | -------------------- | ---- | ---------------------------------------- |
A
Annie_wang 已提交
271 272
| type     | 'deviceChange'&#124;<br>'albumChange'&#124;<br>'imageChange'&#124;<br>'audioChange'&#124;<br>'videoChange'&#124;<br>'fileChange'&#124;<br>'remoteFileChange'               | Yes   | Type of the event to unsubscribe from.<br>'deviceChange': registered device change<br>'albumChange': album change<br>'imageChange': image file change<br>'audioChange': audio file change<br>'videoChange': video file change<br>'fileChange': file change<br>'remoteFileChange': file change on the registered device|
| callback | Callback&lt;void&gt; | No   | Callback that returns no value.                                   |
W
wusongqing 已提交
273 274 275

**Example**

276
```js
W
wusongqing 已提交
277
media.off('imageChange', () => {
A
Annie_wang 已提交
278 279
  // stop listening successfully.
});
W
wusongqing 已提交
280 281
```

282
### createAsset<sup>8+</sup>
W
wusongqing 已提交
283 284 285 286 287

createAsset(mediaType: MediaType, displayName: string, relativePath: string, callback: AsyncCallback&lt;FileAsset&gt;): void

Creates a media asset. This API uses an asynchronous callback to return the result.

A
Annie_wang 已提交
288
> **NOTE**
A
Annie_wang 已提交
289 290 291
>
> - This API is deprecated since API Version 9. Use [createAsset](js-apis-photoAccessHelper.md#createasset) instead.
> - From the SDK of API version 10, **relativePath** is no longer associated with an album. After a file is created, the last-level directory of **relativePath** is not displayed. For details, see [changelogs-mediaLibrary.md](../../../release-notes/changelogs/OpenHarmony_4.0.8.2/changelogs-mediaLibrary.md).
A
Annie_wang 已提交
292

W
wusongqing 已提交
293 294 295 296 297 298
**Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
299 300 301
| Name      | Type                                   | Mandatory| Description                                                        |
| ------------ | --------------------------------------- | ---- | ------------------------------------------------------------ |
| mediaType    | [MediaType](#mediatype8)                | Yes  | Media type.                                                    |
A
Annie_wang 已提交
302 303 304
| displayName  | string                                  | Yes  | File name to display.                                                  |
| relativePath | string                                  | Yes  | Path of the file, which can be obtained by using [getPublicDirectory](#getpublicdirectory8).|
| callback     | AsyncCallback<[FileAsset](#fileasset7)> | Yes  | Callback invoked to return the **FileAsset** instance created.                         |
W
wusongqing 已提交
305 306 307

**Example**

308
```js
W
wusongqing 已提交
309
async function example() {
A
Annie_wang 已提交
310 311 312 313 314 315 316 317 318 319 320
  // Create an image file in callback mode.
  let mediaType = mediaLibrary.MediaType.IMAGE;
  let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE;
  const path = await media.getPublicDirectory(DIR_IMAGE);
  media.createAsset(mediaType, 'imageCallBack.jpg', path + 'myPicture/', (error, fileAsset) => {
    if (fileAsset != undefined) {
      console.info('createAsset successfully, message');
    } else {
      console.error('createAsset failed with error: ' + error);
    }
  });
W
wusongqing 已提交
321 322 323 324 325 326 327 328 329
}
```

### createAsset<sup>8+</sup>

createAsset(mediaType: MediaType, displayName: string, relativePath: string): Promise&lt;FileAsset&gt;

Creates a media asset. This API uses a promise to return the result.

A
Annie_wang 已提交
330
> **NOTE**
A
Annie_wang 已提交
331 332 333
>
> - This API is deprecated since API Version 9. Use [createAsset](js-apis-photoAccessHelper.md#createasset-1) instead.
> - From the SDK of API version 10, **relativePath** is no longer associated with an album. After a file is created, the last-level directory of **relativePath** is not displayed. For details, see [changelogs-mediaLibrary.md](../../../release-notes/changelogs/OpenHarmony_4.0.8.2/changelogs-mediaLibrary.md).
A
Annie_wang 已提交
334

W
wusongqing 已提交
335 336 337 338 339 340
**Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
341 342 343
| Name      | Type                    | Mandatory| Description                                                        |
| ------------ | ------------------------ | ---- | ------------------------------------------------------------ |
| mediaType    | [MediaType](#mediatype8) | Yes  | Media type.                                                    |
A
Annie_wang 已提交
344 345
| displayName  | string                   | Yes  | File name to display.                                                  |
| relativePath | string                   | Yes  | Relative path of the file, which can be obtained by [getPublicDirectory](#getpublicdirectory8).|
W
wusongqing 已提交
346 347 348

**Return value**

W
wusongqing 已提交
349 350
| Type                    | Description             |
| ------------------------ | ----------------- |
A
Annie_wang 已提交
351
| Promise&lt;[FileAsset](#fileasset7)&gt; | Promise used to return the **FileAsset** instance created.|
W
wusongqing 已提交
352 353 354

**Example**

355
```js
356
async function example() {
A
Annie_wang 已提交
357 358 359 360 361 362 363 364 365
  // Create an image file in promise mode.
  let mediaType = mediaLibrary.MediaType.IMAGE;
  let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE;
  const path = await media.getPublicDirectory(DIR_IMAGE);
  media.createAsset(mediaType, 'imagePromise.jpg', path + 'myPicture/').then((fileAsset) => {
    console.info('createAsset successfully, message = ' + JSON.stringify(fileAsset));
  }).catch((error) => {
    console.error('createAsset failed with error: ' + error);
  });
366
}
W
wusongqing 已提交
367 368
```

369 370 371 372 373 374
### deleteAsset<sup>8+</sup>

deleteAsset(uri: string): Promise\<void>

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

A
Annie_wang 已提交
375 376 377 378 379
Before calling this API, call [FileAsset.trash](#trash8) to move the file to the trash. Otherwise, the file fails to be deleted.

> **NOTE**
> This API is deprecated since API Version 9. Use [deleteAssets](js-apis-photoAccessHelper.md#deleteassets-3) instead.

380 381 382 383 384 385 386 387 388 389 390 391 392
**System API**: This is a system API.

**Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

| Name     | Type                          | Mandatory  | Description             |
| -------- | ---------------------------- | ---- | --------------- |
| uri | string | Yes   | URI of the file asset to delete.|

**Return value**
A
Annie_wang 已提交
393

394 395 396 397 398 399 400 401
| Type                 | Description                  |
| ------------------- | -------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|

**Example**

```js
async function example() {
A
Annie_wang 已提交
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419
  let fileKeyObj = mediaLibrary.FileKey;
  let fileType = mediaLibrary.MediaType.FILE;
  let option = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [fileType.toString()],
  };
  const fetchFileResult = await media.getFileAssets(option);
  let asset = await fetchFileResult.getFirstObject();
  if (asset == undefined) {
    console.error('asset not exist');
    return;
  }
  media.deleteAsset(asset.uri).then(() => {
    console.info('deleteAsset successfully');
  }).catch((error) => {
    console.error('deleteAsset failed with error: ' + error);
  });
  fetchFileResult.close();
420 421 422 423
}
```

### deleteAsset<sup>8+</sup>
A
Annie_wang 已提交
424

425 426 427 428
deleteAsset(uri: string, callback: AsyncCallback\<void>): void

Deletes a file asset. This API uses an asynchronous callback to return the result.

A
Annie_wang 已提交
429 430 431 432 433
Before calling this API, call [FileAsset.trash](#trash8) to move the file to the trash. Otherwise, the file fails to be deleted.

> **NOTE**
> This API is deprecated since API Version 9. Use [deleteAssets](js-apis-photoAccessHelper.md#deleteassets-2) instead.

434 435 436 437 438 439 440 441 442 443 444
**System API**: This is a system API.

**Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

| Name     | Type                          | Mandatory  | Description             |
| -------- | ---------------------------- | ---- | --------------- |
| uri | string | Yes   | URI of the file asset to delete.|
A
Annie_wang 已提交
445
|callback |AsyncCallback\<void>| Yes |Callback that returns no value.|
446 447 448 449 450

**Example**

```js
async function example() {
A
Annie_wang 已提交
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467
  let fileKeyObj = mediaLibrary.FileKey;
  let fileType = mediaLibrary.MediaType.FILE;
  let option = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [fileType.toString()],
  };
  const fetchFileResult = await media.getFileAssets(option);
  let asset = await fetchFileResult.getFirstObject();
  if (asset == undefined) {
    console.error('asset not exist');
    return;
  }
  media.deleteAsset(asset.uri, (error) => {
    if (error != undefined) {
      console.error('deleteAsset failed with error: ' + error);
    } else {
      console.info('deleteAsset successfully');
468
    }
A
Annie_wang 已提交
469 470
  });
  fetchFileResult.close();
471 472 473
}
```

W
wusongqing 已提交
474 475 476 477
### getPublicDirectory<sup>8+</sup>

getPublicDirectory(type: DirectoryType, callback: AsyncCallback&lt;string&gt;): void

A
Annie_wang 已提交
478
Obtains a user directory. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
479

A
Annie_wang 已提交
480 481 482
> **NOTE**
> This API is deprecated since API Version 9. There is no substitute API.

W
wusongqing 已提交
483 484 485 486
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
487 488
| Name  | Type                            | Mandatory| Description                     |
| -------- | -------------------------------- | ---- | ------------------------- |
A
Annie_wang 已提交
489 490
| type     | [DirectoryType](#directorytype8) | Yes  | Type of the user directory.             |
| callback | AsyncCallback&lt;string&gt;      | Yes  | Callback invoked to return the user directory obtained.|
W
wusongqing 已提交
491 492 493

**Example**

494
```js
W
wusongqing 已提交
495
let DIR_CAMERA = mediaLibrary.DirectoryType.DIR_CAMERA;
G
Gloria 已提交
496
media.getPublicDirectory(DIR_CAMERA, (error, dicResult) => {
A
Annie_wang 已提交
497 498 499 500 501
  if (dicResult == 'Camera/') {
    console.info('getPublicDirectory DIR_CAMERA successfully');
  } else {
    console.error('getPublicDirectory DIR_CAMERA failed with error: ' + error);
  }
W
wusongqing 已提交
502 503 504 505 506 507 508
});
```

### getPublicDirectory<sup>8+</sup>

getPublicDirectory(type: DirectoryType): Promise&lt;string&gt;

A
Annie_wang 已提交
509
Obtains a user directory. This API uses a promise to return the result.
W
wusongqing 已提交
510

A
Annie_wang 已提交
511 512 513
> **NOTE**
> This API is deprecated since API Version 9. There is no substitute API.

W
wusongqing 已提交
514 515 516 517
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
518 519
| Name| Type                            | Mandatory| Description        |
| ------ | -------------------------------- | ---- | ------------ |
A
Annie_wang 已提交
520
| type   | [DirectoryType](#directorytype8) | Yes  | Type of the user directory.|
W
wusongqing 已提交
521 522 523

**Return value**

W
wusongqing 已提交
524 525
| Type            | Description            |
| ---------------- | ---------------- |
A
Annie_wang 已提交
526
| Promise\<string> | Promise used to return the user directory obtained.|
W
wusongqing 已提交
527 528 529

**Example**

530
```js
W
wusongqing 已提交
531
async function example() {
A
Annie_wang 已提交
532 533 534 535 536 537 538 539 540 541
  let DIR_CAMERA = mediaLibrary.DirectoryType.DIR_CAMERA;
  media.getPublicDirectory(DIR_CAMERA).then((dicResult) => {
    if (dicResult == 'Camera/') {
      console.info('getPublicDirectory DIR_CAMERA successfully');
    } else {
      console.error('getPublicDirectory DIR_CAMERA failed');
    }
  }).catch((error) => {
    console.error('getPublicDirectory failed with error: ' + error);
  });
W
wusongqing 已提交
542 543 544
}
```

W
wusongqing 已提交
545
### getAlbums<sup>7+</sup>
W
wusongqing 已提交
546

G
Gloria 已提交
547
getAlbums(options: MediaFetchOptions, callback: AsyncCallback&lt;Array&lt;Album&gt;&gt;): void
W
wusongqing 已提交
548

A
Annie_wang 已提交
549 550 551
Obtains albums. This API uses an asynchronous callback to return the result.

> **NOTE**
A
Annie_wang 已提交
552 553 554
>
> - This API is deprecated since API Version 9. Use [getAlbums](js-apis-photoAccessHelper.md#getalbums) instead.
> - From the SDK of API version 10, **relativePath** is no longer associated with an album. Therefore, **relativePath** cannot be used as a search criterion in **getAlbums**. Currently, only **Camera** and **ScreenShots** albums are supported. For more details, see [changelogs-mediaLibrary.md](../../../release-notes/changelogs/OpenHarmony_4.0.8.2/changelogs-mediaLibrary.md).
W
wusongqing 已提交
555 556 557 558 559 560 561

**Required permissions**: ohos.permission.READ_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
562 563
| Name  | Type                                        | Mandatory| Description                       |
| -------- | -------------------------------------------- | ---- | --------------------------- |
A
Annie_wang 已提交
564 565
| options  | [MediaFetchOptions](#mediafetchoptions7)     | Yes  | Options for fetching albums.               |
| callback | AsyncCallback&lt;Array<[Album](#album7)>&gt; | Yes  | Callback invoked to return the albums.|
W
wusongqing 已提交
566 567 568

**Example**

569
```js
G
Gloria 已提交
570
async function example() {
571 572
  let AlbumNoArgsfetchOp = {
    selections: mediaLibrary.FileKey.ALBUM_NAME + '= ?',
A
Annie_wang 已提交
573
    selectionArgs: ['Camera'],
574 575 576 577 578 579 580
  };
  media.getAlbums(AlbumNoArgsfetchOp, (error, albumList) => {
    if (albumList != undefined) {
      console.info('getAlbums successfully: ' + JSON.stringify(albumList));
    } else {
      console.error('getAlbums failed with error: ' + error);
    }
A
Annie_wang 已提交
581
  });
G
Gloria 已提交
582
}
W
wusongqing 已提交
583 584
```

W
wusongqing 已提交
585
### getAlbums<sup>7+</sup>
W
wusongqing 已提交
586

G
Gloria 已提交
587
getAlbums(options: MediaFetchOptions): Promise&lt;Array&lt;Album&gt;&gt;
W
wusongqing 已提交
588

A
Annie_wang 已提交
589 590 591
Obtains albums. This API uses a promise to return the result.

> **NOTE**
A
Annie_wang 已提交
592 593 594
>
> - This API is deprecated since API Version 9. Use [getAlbums](js-apis-photoAccessHelper.md#getalbums-2) instead.
> - From the SDK of API version 10, **relativePath** is no longer associated with an album. Therefore, **relativePath** cannot be used as a search criterion in **getAlbums**. Currently, only **Camera** and **ScreenShots** albums are supported. For more details, see [changelogs-mediaLibrary.md](../../../release-notes/changelogs/OpenHarmony_4.0.8.2/changelogs-mediaLibrary.md).
W
wusongqing 已提交
595 596 597 598 599 600 601

**Required permissions**: ohos.permission.READ_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
602 603 604
| Name | Type                                    | Mandatory| Description        |
| ------- | ---------------------------------------- | ---- | ------------ |
| options | [MediaFetchOptions](#mediafetchoptions7) | Yes  | Options for fetching the albums.|
W
wusongqing 已提交
605 606 607

**Return value**

W
wusongqing 已提交
608 609 610
| Type                            | Description         |
| -------------------------------- | ------------- |
| Promise<Array<[Album](#album7)>> | Promise used to return the albums.|
W
wusongqing 已提交
611 612 613

**Example**

614
```js
G
Gloria 已提交
615
async function example() {
616 617
  let AlbumNoArgsfetchOp = {
    selections: mediaLibrary.FileKey.ALBUM_NAME + '= ?',
A
Annie_wang 已提交
618
    selectionArgs: ['Camera'],
619 620 621 622 623 624
  };
  media.getAlbums(AlbumNoArgsfetchOp).then((albumList) => {
    console.info('getAlbums successfully: ' + JSON.stringify(albumList));
  }).catch((error) => {
    console.error('getAlbums failed with error: ' + error);
  });
G
Gloria 已提交
625
}
W
wusongqing 已提交
626 627 628 629 630 631 632 633 634
```

### release<sup>8+</sup>

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

Releases this **MediaLibrary** instance.
Call this API when you no longer need to use the APIs in the **MediaLibrary** instance.

A
Annie_wang 已提交
635 636 637
> **NOTE**
> This API is deprecated since API Version 9. Use [release](js-apis-photoAccessHelper.md#release) instead.

W
wusongqing 已提交
638 639 640 641
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
642 643
| Name     | Type                       | Mandatory  | Description        |
| -------- | ------------------------- | ---- | ---------- |
G
Gloria 已提交
644
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback that returns no value.|
W
wusongqing 已提交
645 646 647

**Example**

648
```js
G
Gloria 已提交
649
media.release(() => {
A
Annie_wang 已提交
650
  // do something.
W
wusongqing 已提交
651 652 653 654 655 656 657 658 659 660
});
```

### release<sup>8+</sup>

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

Releases this **MediaLibrary** instance.
Call this API when you no longer need to use the APIs in the **MediaLibrary** instance.

A
Annie_wang 已提交
661 662 663
> **NOTE**
> This API is deprecated since API Version 9. Use [release](js-apis-photoAccessHelper.md#release-1) instead.

W
wusongqing 已提交
664 665 666 667
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Return value**

W
wusongqing 已提交
668 669
| Type                 | Description                  |
| ------------------- | -------------------- |
A
Annie_wang 已提交
670
| Promise&lt;void&gt; | Promise that returns no value.|
W
wusongqing 已提交
671 672 673

**Example**

674
```js
A
Annie_wang 已提交
675
media.release();
W
wusongqing 已提交
676 677
```

G
Gloria 已提交
678
### storeMediaAsset
W
wusongqing 已提交
679 680 681

storeMediaAsset(option: MediaAssetOption, callback: AsyncCallback&lt;string&gt;): void

A
Annie_wang 已提交
682
Stores a media asset. This API uses an asynchronous callback to return the URI of the media asset.
W
wusongqing 已提交
683

A
Annie_wang 已提交
684 685 686 687
> **NOTE**
>
> - This API is supported since API version 6 and can be used only in the FA model.
> - This API is deprecated since API Version 9. Use [save](js-apis-file-picker.md#save-1) instead.
W
wusongqing 已提交
688 689 690 691 692

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
693 694 695
| Name     | Type                                   | Mandatory  | Description                     |
| -------- | ------------------------------------- | ---- | ----------------------- |
| option   | [MediaAssetOption](#mediaassetoption) | Yes   | Media asset option.                |
A
Annie_wang 已提交
696
| callback | AsyncCallback&lt;string&gt;           | Yes   | Callback invoked to return the URI of the media resource saved.|
W
wusongqing 已提交
697 698 699

**Example**

700
```js
W
wusongqing 已提交
701
let option = {
A
Annie_wang 已提交
702 703 704
  src : '/data/storage/el2/base/haps/entry/image.png',
  mimeType : 'image/*',
  relativePath : 'Pictures/'
W
wusongqing 已提交
705
};
G
Gloria 已提交
706
mediaLibrary.getMediaLibrary().storeMediaAsset(option, (error, value) => {
A
Annie_wang 已提交
707 708 709 710 711 712
  if (error) {
    console.error('storeMediaAsset failed with error: ' + error);
    return;
  }
  console.info('Media resources stored. ');
  // Obtain the URI of the media asset.
W
wusongqing 已提交
713
});
714
```
W
wusongqing 已提交
715

G
Gloria 已提交
716
### storeMediaAsset
W
wusongqing 已提交
717 718 719

storeMediaAsset(option: MediaAssetOption): Promise&lt;string&gt;

A
Annie_wang 已提交
720
Stores a media asset. This API uses a promise to return the URI of the media asset.
W
wusongqing 已提交
721

A
Annie_wang 已提交
722 723 724 725
> **NOTE**
>
> - This API is supported since API version 6 and can be used only in the FA model.
> - This API is deprecated since API Version 9. Use [save](js-apis-file-picker.md#save) instead.
W
wusongqing 已提交
726 727 728 729 730

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
731 732 733
| Name   | Type                                   | Mandatory  | Description     |
| ------ | ------------------------------------- | ---- | ------- |
| option | [MediaAssetOption](#mediaassetoption) | Yes   | Media asset option.|
W
wusongqing 已提交
734 735 736

**Return value**

W
wusongqing 已提交
737 738
| Type                   | Description                          |
| --------------------- | ---------------------------- |
A
Annie_wang 已提交
739
| Promise&lt;string&gt; | Promise used to return the URI of the media asset saved.|
W
wusongqing 已提交
740 741 742

**Example**

743
```js
W
wusongqing 已提交
744
let option = {
A
Annie_wang 已提交
745 746 747
  src : '/data/storage/el2/base/haps/entry/image.png',
  mimeType : 'image/*',
  relativePath : 'Pictures/'
W
wusongqing 已提交
748 749
};
mediaLibrary.getMediaLibrary().storeMediaAsset(option).then((value) => {
A
Annie_wang 已提交
750 751
  console.info('Media resources stored.');
  // Obtain the URI of the media asset.
G
Gloria 已提交
752
}).catch((error) => {
A
Annie_wang 已提交
753
  console.error('storeMediaAsset failed with error: ' + error);
W
wusongqing 已提交
754
});
755
```
W
wusongqing 已提交
756

G
Gloria 已提交
757
### startImagePreview
W
wusongqing 已提交
758 759 760

startImagePreview(images: Array&lt;string&gt;, index: number, callback: AsyncCallback&lt;void&gt;): void

A
Annie_wang 已提交
761
Starts image preview, with the first image to preview specified. This API can be used to preview local images whose URIs start with **datashare://** or online images whose URIs start with **https://**. It uses an asynchronous callback to return the result.
W
wusongqing 已提交
762

W
wusongqing 已提交
763
> **NOTE**
A
Annie_wang 已提交
764 765 766
>
> - This API is supported since API version 6 and can be used only in the FA model.
> - This API is deprecated since API Version 9. You are advised to use the **\<[Image](../arkui-ts/ts-basic-components-image.md)>** component instead. <br>The **\<Image>** component can be used to render and display local and online images.
W
wusongqing 已提交
767 768 769 770 771

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
772 773
| Name     | Type                       | Mandatory  | Description                                      |
| -------- | ------------------------- | ---- | ---------------------------------------- |
G
Gloria 已提交
774
| images   | Array&lt;string&gt;       | Yes   | URIs of the images to preview. The value can start with either **'https://'** or **'datashare://'**.|
W
wusongqing 已提交
775
| index    | number                    | Yes   | Index of the first image to preview.                              |
A
Annie_wang 已提交
776
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback that returns no value.                       |
W
wusongqing 已提交
777 778 779

**Example**

780
```js
W
wusongqing 已提交
781
let images = [
A
Annie_wang 已提交
782 783
  'file://media/xxxx/2',
  'file://media/xxxx/3'
W
wusongqing 已提交
784
];
W
wusongqing 已提交
785
/* Preview online images.
W
wusongqing 已提交
786
let images = [
A
Annie_wang 已提交
787 788
  'https://media.xxxx.com/image1.jpg',
  'https://media.xxxx.com/image2.jpg'
W
wusongqing 已提交
789
];
W
wusongqing 已提交
790
*/
W
wusongqing 已提交
791
let index = 1;
G
Gloria 已提交
792
mediaLibrary.getMediaLibrary().startImagePreview(images, index, (error) => {
A
Annie_wang 已提交
793 794 795 796 797
  if (error) {
    console.error('startImagePreview failed with error: ' + error);
    return;
  }
  console.info('Succeeded in previewing the images.');
W
wusongqing 已提交
798
});
799
```
W
wusongqing 已提交
800

G
Gloria 已提交
801
### startImagePreview
W
wusongqing 已提交
802 803 804

startImagePreview(images: Array&lt;string&gt;, callback: AsyncCallback&lt;void&gt;): void

A
Annie_wang 已提交
805
Starts image preview. This API can be used to preview local images whose URIs start with **datashare://** or online images whose URIs start with **https://**. It uses an asynchronous callback to return the result.
W
wusongqing 已提交
806

W
wusongqing 已提交
807
> **NOTE**
A
Annie_wang 已提交
808 809 810
>
> - This API is supported since API version 6 and can be used only in the FA model.
> - This API is deprecated since API Version 9. You are advised to use the **\<[Image](../arkui-ts/ts-basic-components-image.md)>** component instead. <br>The **\<Image>** component can be used to render and display local and online images.
W
wusongqing 已提交
811 812 813 814 815

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
816 817
| Name     | Type                       | Mandatory  | Description                                      |
| -------- | ------------------------- | ---- | ---------------------------------------- |
G
Gloria 已提交
818
| images   | Array&lt;string&gt;       | Yes   | URIs of the images to preview. The value can start with either **'https://'** or **'datashare://'**.|
A
Annie_wang 已提交
819
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback that returns no value.                       |
W
wusongqing 已提交
820 821 822

**Example**

823
```js
W
wusongqing 已提交
824
let images = [
A
Annie_wang 已提交
825 826
  'file://media/xxxx/2',
  'file://media/xxxx/3'
W
wusongqing 已提交
827
];
W
wusongqing 已提交
828
/* Preview online images.
W
wusongqing 已提交
829
let images = [
A
Annie_wang 已提交
830 831
  'https://media.xxxx.com/image1.jpg',
  'https://media.xxxx.com/image2.jpg'
W
wusongqing 已提交
832
];
W
wusongqing 已提交
833
*/
G
Gloria 已提交
834
mediaLibrary.getMediaLibrary().startImagePreview(images, (error) => {
A
Annie_wang 已提交
835 836 837 838 839
  if (error) {
    console.error('startImagePreview failed with error: ' + error);
    return;
  }
  console.info('Succeeded in previewing the images.');
W
wusongqing 已提交
840
});
841
```
W
wusongqing 已提交
842

G
Gloria 已提交
843
### startImagePreview
W
wusongqing 已提交
844 845 846

startImagePreview(images: Array&lt;string&gt;, index?: number): Promise&lt;void&gt;

847
Starts image preview, with the first image to preview specified. This API can be used to preview local images whose URIs start with **datashare://** or online images whose URIs start with **https://**. It uses a promise to return the execution result.
W
wusongqing 已提交
848

W
wusongqing 已提交
849
> **NOTE**
A
Annie_wang 已提交
850 851 852
>
> - This API is supported since API version 6 and can be used only in the FA model.
> - This API is deprecated since API Version 9. You are advised to use the **\<[Image](../arkui-ts/ts-basic-components-image.md)>** component instead. <br>The **\<Image>** component can be used to render and display local and online images.
W
wusongqing 已提交
853 854 855 856 857

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
858 859
| Name   | Type                 | Mandatory  | Description                                      |
| ------ | ------------------- | ---- | ---------------------------------------- |
G
Gloria 已提交
860
| images | Array&lt;string&gt; | Yes   | URIs of the images to preview. The value can start with either **'https://'** or **'datashare://'**.|
W
wusongqing 已提交
861
| index  | number              | No   | Index of the first image to preview. If this parameter is not specified, the default value **0** is used.                     |
W
wusongqing 已提交
862 863 864

**Return value**

W
wusongqing 已提交
865 866
| Type                 | Description                             |
| ------------------- | ------------------------------- |
A
Annie_wang 已提交
867
| Promise&lt;void&gt; | Promise that returns no value.|
W
wusongqing 已提交
868 869 870

**Example**

871
```js
W
wusongqing 已提交
872
let images = [
A
Annie_wang 已提交
873 874
  'file://media/xxxx/2',
  'file://media/xxxx/3'
W
wusongqing 已提交
875
];
W
wusongqing 已提交
876
/* Preview online images.
W
wusongqing 已提交
877
let images = [
A
Annie_wang 已提交
878 879
  'https://media.xxxx.com/image1.jpg',
  'https://media.xxxx.com/image2.jpg'
W
wusongqing 已提交
880
];
W
wusongqing 已提交
881
*/
W
wusongqing 已提交
882 883
let index = 1;
mediaLibrary.getMediaLibrary().startImagePreview(images, index).then(() => {
A
Annie_wang 已提交
884
  console.info('Succeeded in previewing the images.');
G
Gloria 已提交
885
}).catch((error) => {
A
Annie_wang 已提交
886
  console.error('startImagePreview failed with error: ' + error);
W
wusongqing 已提交
887
});
888
```
W
wusongqing 已提交
889

G
Gloria 已提交
890
### startMediaSelect
W
wusongqing 已提交
891 892 893

startMediaSelect(option: MediaSelectOption, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void

A
Annie_wang 已提交
894
Starts media selection. This API uses an asynchronous callback to return the URIs of the selected media assets.
W
wusongqing 已提交
895

W
wusongqing 已提交
896
> **NOTE**
A
Annie_wang 已提交
897 898 899
>
> - This API is supported since API version 6 and can be used only in the FA model.
> - This API is deprecated since API Version 9. Use [select](js-apis-file-picker.md#select-1) instead.
W
wusongqing 已提交
900 901 902 903 904

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
905 906
| Name     | Type                                      | Mandatory  | Description                                  |
| -------- | ---------------------------------------- | ---- | ------------------------------------ |
G
Gloria 已提交
907
| option   | [MediaSelectOption](#mediaselectoption)  | Yes   | Media selection option.                             |
A
Annie_wang 已提交
908
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | Yes   | Callback invoked to return the URIs of the selected media assets.|
W
wusongqing 已提交
909 910 911

**Example**

912 913
```js
let option : mediaLibrary.MediaSelectOption = {
A
Annie_wang 已提交
914 915
  type : 'media',
  count : 2
W
wusongqing 已提交
916
};
G
Gloria 已提交
917
mediaLibrary.getMediaLibrary().startMediaSelect(option, (error, value) => {
A
Annie_wang 已提交
918 919 920 921 922 923
  if (error) {
    console.error('startMediaSelect failed with error: ' + error);
    return;
  }
  console.info('Media resources selected.');
  // Obtain the media selection value.
W
wusongqing 已提交
924
});
925
```
W
wusongqing 已提交
926

G
Gloria 已提交
927
### startMediaSelect
W
wusongqing 已提交
928 929 930

startMediaSelect(option: MediaSelectOption): Promise&lt;Array&lt;string&gt;&gt;

A
Annie_wang 已提交
931
Starts media selection. This API uses a promise to return the URIs of the selected media assets.
W
wusongqing 已提交
932

W
wusongqing 已提交
933
> **NOTE**
A
Annie_wang 已提交
934 935 936
>
> - This API is supported since API version 6 and can be used only in the FA model.
> - This API is deprecated since API Version 9. Use [select](js-apis-file-picker.md#select) instead.
W
wusongqing 已提交
937 938 939 940 941

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
942 943
| Name   | Type                                     | Mandatory  | Description     |
| ------ | --------------------------------------- | ---- | ------- |
G
Gloria 已提交
944
| option | [MediaSelectOption](#mediaselectoption) | Yes   | Media selection option.|
W
wusongqing 已提交
945 946 947

**Return value**

W
wusongqing 已提交
948 949
| Type                                | Description                                      |
| ---------------------------------- | ---------------------------------------- |
A
Annie_wang 已提交
950
| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return the URIs of the selected media assets.|
W
wusongqing 已提交
951 952 953

**Example**

954 955
```js
let option : mediaLibrary.MediaSelectOption = {
A
Annie_wang 已提交
956 957
  type : 'media',
  count : 2
W
wusongqing 已提交
958 959
};
mediaLibrary.getMediaLibrary().startMediaSelect(option).then((value) => {
A
Annie_wang 已提交
960 961
  console.info('Media resources selected.');
  // Obtain the media selection value.
G
Gloria 已提交
962
}).catch((error) => {
A
Annie_wang 已提交
963
  console.error('startMediaSelect failed with error: ' + error);
W
wusongqing 已提交
964
});
965
```
A
Annie_wang 已提交
966

967 968 969 970 971 972
### getActivePeers<sup>8+</sup>

getActivePeers(): Promise\<Array\<PeerInfo>>;

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

A
Annie_wang 已提交
973 974 975
> **NOTE**
> This API is deprecated since API Version 9. There is no substitute API.

976 977 978 979 980 981 982 983 984 985
**System API**: This is a system API.

**Required permissions**: ohos.permission.READ_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.DistributedCore

**Return value**

| Type                 | Description                  |
| ------------------- | -------------------- |
G
gloria 已提交
986
|  Promise\<Array\<[PeerInfo](#peerinfo8)>> | Promise used to return the online peer devices, in an array of **PeerInfo** objects.|
987 988 989 990 991

**Example**

```js
async function example() {
A
Annie_wang 已提交
992 993 994 995 996 997 998 999 1000
  media.getActivePeers().then((devicesInfo) => {
    if (devicesInfo != undefined) {
      console.info('get distributed info ' + JSON.stringify(devicesInfo));
    } else {
      console.info('get distributed info is undefined!');
    }
  }).catch((error) => {
    console.error('get distributed info failed with error: ' + error);
  });
1001 1002 1003 1004 1005 1006 1007 1008 1009
}
```

### getActivePeers<sup>8+</sup>

getActivePeers(callback: AsyncCallback\<Array\<PeerInfo>>): void;

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

A
Annie_wang 已提交
1010 1011 1012
> **NOTE**
> This API is deprecated since API Version 9. There is no substitute API.

1013 1014 1015 1016 1017 1018 1019 1020 1021 1022
**System API**: This is a system API.

**Required permissions**: ohos.permission.READ_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.DistributedCore

**Return value**

| Type                 | Description                  |
| ------------------- | -------------------- |
A
Annie_wang 已提交
1023
| callback: AsyncCallback\<Array\<[PeerInfo](#peerinfo8)>> | Callback invoked to return the online peer devices, in an array of **PeerInfo** objects.|
1024 1025 1026 1027 1028

**Example**

```js
async function example() {
A
Annie_wang 已提交
1029 1030 1031 1032 1033 1034 1035
  media.getActivePeers((error, devicesInfo) => {
    if (devicesInfo != undefined) {
      console.info('get distributed info ' + JSON.stringify(devicesInfo));
    } else {
      console.error('get distributed failed with error: ' + error);
    }
  });
1036 1037 1038 1039 1040 1041 1042 1043 1044
}
```

### getAllPeers<sup>8+</sup>

getAllPeers(): Promise\<Array\<PeerInfo>>;

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

A
Annie_wang 已提交
1045 1046 1047
> **NOTE**
> This API is deprecated since API Version 9. There is no substitute API.

1048 1049 1050 1051 1052 1053 1054 1055 1056 1057
**System API**: This is a system API.

**Required permissions**: ohos.permission.READ_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.DistributedCore

**Return value**

| Type                 | Description                  |
| ------------------- | -------------------- |
G
gloria 已提交
1058
|  Promise\<Array\<[PeerInfo](#peerinfo8)>> | Promise used to return all peer devices, in an array of **PeerInfo** objects.|
1059 1060 1061 1062 1063

**Example**

```js
async function example() {
A
Annie_wang 已提交
1064 1065 1066 1067 1068 1069 1070 1071 1072
  media.getAllPeers().then((devicesInfo) => {
    if (devicesInfo != undefined) {
      console.info('get distributed info ' + JSON.stringify(devicesInfo));
    } else {
      console.info('get distributed info is undefined!');
    }
  }).catch((error) => {
    console.error('get distributed info failed with error: ' + error);
  });
1073 1074 1075 1076 1077 1078 1079
}
```

### getAllPeers<sup>8+</sup>

getAllPeers(callback: AsyncCallback\<Array\<PeerInfo>>): void;

A
Annie_wang 已提交
1080
Obtains information about all peer devices. This API uses an asynchronous callback to return the result.
1081

A
Annie_wang 已提交
1082 1083 1084
> **NOTE**
> This API is deprecated since API Version 9. There is no substitute API.

1085 1086 1087 1088 1089 1090 1091 1092 1093 1094
**System API**: This is a system API.

**Required permissions**: ohos.permission.READ_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.DistributedCore

**Return value**

| Type                 | Description                  |
| ------------------- | -------------------- |
A
Annie_wang 已提交
1095
| callback: AsyncCallback\<Array\<[PeerInfo](#peerinfo8)>> | Callback invoked to return all peer devices, in an array of **PeerInfo** objects.|
1096 1097 1098 1099 1100

**Example**

```js
async function example() {
A
Annie_wang 已提交
1101 1102 1103 1104 1105 1106 1107
  media.getAllPeers((error, devicesInfo) => {
    if (devicesInfo != undefined) {
      console.info('get distributed info ' + JSON.stringify(devicesInfo));
    } else {
      console.error('get distributed failed with error: ' + error);
    }
  });
1108 1109
}
```
W
wusongqing 已提交
1110

W
wusongqing 已提交
1111
## FileAsset<sup>7+</sup>
W
wusongqing 已提交
1112 1113 1114

Provides APIs for encapsulating file asset attributes.

G
gloria 已提交
1115
> **NOTE**
A
Annie_wang 已提交
1116
>
A
Annie_wang 已提交
1117 1118 1119
> - The system attempts to parse the file content if the file is an audio or video file. The actual field values will be restored from the passed values during scanning on some devices.
> - Some devices may not support the modification of **orientation**. You are advised to use [ModifyImageProperty](js-apis-image.md#modifyimageproperty9) of the **image** module.
> - This API is deprecated since API Version 9. Use [PhotoAsset](js-apis-photoAccessHelper.md#photoasset) instead.
G
gloria 已提交
1120

W
wusongqing 已提交
1121 1122 1123 1124
### Attributes

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

W
wusongqing 已提交
1125
| Name                     | Type                    | Readable| Writable| Description                                                  |
W
wusongqing 已提交
1126
| ------------------------- | ------------------------ | ---- | ---- | ------------------------------------------------------ |
W
wusongqing 已提交
1127
| id                        | number                   | Yes  | No  | File asset ID.                                          |
L
lvyuanyuan 已提交
1128
| uri                       | string                   | Yes  | No  | File asset URI, for example, **file://media/image/2**.        |
W
wusongqing 已提交
1129 1130
| mimeType                  | string                   | Yes  | No  | Extended file attributes.                                          |
| mediaType<sup>8+</sup>    | [MediaType](#mediatype8) | Yes  | No  | Media type.                                              |
A
Annie_wang 已提交
1131 1132 1133 1134
| displayName               | string                   | Yes  | Yes  | File name, including the file name extension, to display.                                |
| title                     | string                   | Yes  | Yes  | Title in the file.                                              |
| relativePath<sup>8+</sup> | string                   | Yes  | Yes  | Relative path of the user directory.                                      |
| parent<sup>8+</sup>       | number                   | Yes  | No  | Parent directory ID. Since SDK of API version 10, an asset can exist in multiple albums. Therefore, this attribute is incompatible. The obtained value is always **0**.                       |
W
wusongqing 已提交
1135
| size                      | number                   | Yes  | No  | File size, in bytes.                                |
G
Gloria 已提交
1136 1137 1138
| dateAdded                 | number                   | Yes  | No  | Date when the file was added. The value is the number of seconds elapsed since the Epoch time.        |
| dateModified              | number                   | Yes  | No  | Date when the file content (not the file name) was last modified. The value is the number of seconds elapsed since the Epoch time.|
| dateTaken                 | number                   | Yes  | No  | Date when the file (photo) was taken. The value is the number of seconds elapsed since the Epoch time.        |
W
wusongqing 已提交
1139 1140 1141 1142 1143
| artist<sup>8+</sup>       | string                   | Yes  | No  | Artist of the file.                                                  |
| audioAlbum<sup>8+</sup>   | string                   | Yes  | No  | Audio album.                                                  |
| width                     | number                   | Yes  | No  | Image width, in pixels.                                |
| height                    | number                   | Yes  | No  | Image height, in pixels.                                |
| orientation               | number                   | Yes  | Yes  | Image display direction (clockwise rotation angle, for example, 0, 90, or 180, in degrees).|
W
wusongqing 已提交
1144
| duration<sup>8+</sup>     | number                   | Yes  | No  | Duration, in ms.                                  |
A
Annie_wang 已提交
1145 1146 1147
| albumId                   | number                   | Yes  | No  | ID of the album to which the file belongs. Since SDK of API version 10, an asset can exist in multiple albums. Therefore, this attribute is incompatible. The obtained value is always **0**.                  |
| albumUri<sup>8+</sup>     | string                   | Yes  | No  | URI of the album to which the file belongs. Since SDK of API version 10, an asset can exist in multiple albums. Therefore, this attribute is incompatible. The obtained value is always an empty string.                     |
| albumName                 | string                   | Yes  | No  | Name of the album to which the file belongs. Since SDK of API version 10, an asset can exist in multiple albums. Therefore, this attribute is incompatible. The obtained value is always an empty string.                    |
W
wusongqing 已提交
1148 1149 1150 1151 1152 1153 1154

### isDirectory<sup>8+</sup>

isDirectory(callback: AsyncCallback&lt;boolean&gt;): void

Checks whether this file asset is a directory. This API uses an asynchronous callback to return the result.

A
Annie_wang 已提交
1155 1156 1157
> **NOTE**
> This API is deprecated since API Version 9. There is no substitute API.

W
wusongqing 已提交
1158 1159 1160 1161 1162 1163
**Required permissions**: ohos.permission.READ_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
1164
| Name     | Type                          | Mandatory  | Description                 |
W
wusongqing 已提交
1165
| -------- | ---------------------------- | ---- | ------------------- |
A
Annie_wang 已提交
1166
| callback | AsyncCallback&lt;boolean&gt; | Yes   | Callback invoked to return the result. The value **true** means the file asset is a directory; the value false means the opposite.|
W
wusongqing 已提交
1167 1168 1169

**Example**

1170
```js
W
wusongqing 已提交
1171
async function example() {
A
Annie_wang 已提交
1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  const fetchFileResult = await media.getFileAssets(getImageOp);
  const asset = await fetchFileResult.getFirstObject();
  asset.isDirectory((error, isDirectory) => {
    if (error) {
      console.error('isDirectory failed with error: ' + error);
    } else {
      console.info('isDirectory result:' + isDirectory);
    }
  });
  fetchFileResult.close();
W
wusongqing 已提交
1189 1190 1191 1192 1193 1194 1195 1196 1197
}
```

### isDirectory<sup>8+</sup>

isDirectory():Promise&lt;boolean&gt;

Checks whether this file asset is a directory. This API uses a promise to return the result.

A
Annie_wang 已提交
1198 1199 1200
> **NOTE**
> This API is deprecated since API Version 9. There is no substitute API.

W
wusongqing 已提交
1201 1202 1203 1204 1205 1206
**Required permissions**: ohos.permission.READ_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Return value**

W
wusongqing 已提交
1207 1208
| Type                    | Description                          |
| ---------------------- | ---------------------------- |
A
Annie_wang 已提交
1209
| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means the file asset is a directory; the value **false** means the opposite.|
W
wusongqing 已提交
1210 1211 1212

**Example**

1213
```js
W
wusongqing 已提交
1214
async function example() {
A
Annie_wang 已提交
1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  const fetchFileResult = await media.getFileAssets(getImageOp);
  const asset = await fetchFileResult.getFirstObject();
  asset.isDirectory().then((isDirectory) => {
    console.info('isDirectory result:' + isDirectory);
  }).catch((error) => {
    console.error('isDirectory failed with error: ' + error);
  });
  fetchFileResult.close();
W
wusongqing 已提交
1230 1231 1232 1233 1234 1235 1236
}
```

### commitModify<sup>8+</sup>

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

A
Annie_wang 已提交
1237 1238 1239
Commits the modification on the file metadata to the database. This API uses an asynchronous callback to return the result.

> **NOTE**
A
Annie_wang 已提交
1240 1241 1242
>
> - This API is deprecated since API Version 9. Use [commitModify](js-apis-photoAccessHelper.md#commitmodify) instead.
> - Since the SDK of API version 10, **audio** does not have the **orientation** attribute. Therefore, the **orientation** attribute of the audio resource cannot be modified by **commitModify()**. For details, see [changelogs-mediaLibrary.md](../../../release-notes/changelogs/OpenHarmony_4.0.8.2/changelogs-mediaLibrary.md).
W
wusongqing 已提交
1243 1244 1245 1246 1247 1248 1249

**Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
1250 1251
| Name     | Type                       | Mandatory  | Description   |
| -------- | ------------------------- | ---- | ----- |
A
Annie_wang 已提交
1252
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback that returns no value.|
W
wusongqing 已提交
1253 1254 1255

**Example**

1256
```js
W
wusongqing 已提交
1257
async function example() {
A
Annie_wang 已提交
1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  const fetchFileResult = await media.getFileAssets(getImageOp);
  const asset = await fetchFileResult.getFirstObject();
  asset.title = 'newtitle';
  asset.commitModify(() => {
    console.info('commitModify successfully');
  });
  fetchFileResult.close();
W
wusongqing 已提交
1272 1273 1274 1275 1276 1277 1278
}
```

### commitModify<sup>8+</sup>

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

A
Annie_wang 已提交
1279 1280 1281
Commits the modification on the file asset to the database. This API uses a promise to return the result.

> **NOTE**
A
Annie_wang 已提交
1282 1283
>
> - This API is deprecated since API Version 9. Use [commitModify](js-apis-photoAccessHelper.md#commitmodify-1) instead.
A
Annie_wang 已提交
1284
> Since the SDK of API version 10, **audio** does not have the **orientation** attribute. Therefore, the **orientation** attribute of the audio resource cannot be modified by **commitModify()**. For details, see [changelogs-mediaLibrary.md](../../../release-notes/changelogs/OpenHarmony_4.0.8.2/changelogs-mediaLibrary.md).
W
wusongqing 已提交
1285 1286 1287 1288 1289 1290 1291

**Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Return value**

W
wusongqing 已提交
1292 1293
| Type                 | Description        |
| ------------------- | ---------- |
A
Annie_wang 已提交
1294
| Promise&lt;void&gt; | Promise that returns no value.|
W
wusongqing 已提交
1295 1296 1297

**Example**

1298
```js
W
wusongqing 已提交
1299
async function example() {
A
Annie_wang 已提交
1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  const fetchFileResult = await media.getFileAssets(getImageOp);
  const asset = await fetchFileResult.getFirstObject();
  asset.title = 'newtitle';
  await asset.commitModify();
  fetchFileResult.close();
W
wusongqing 已提交
1312 1313 1314 1315 1316 1317 1318 1319 1320
}
```

### open<sup>8+</sup>

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

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

A
Annie_wang 已提交
1321 1322 1323
> **NOTE**
> This API is deprecated since API Version 9. Use [open](js-apis-photoAccessHelper.md#open) instead.

A
Annie_wang 已提交
1324
**NOTE**<br>If a file is opened in 'w' mode, the returned file descriptor (FD) cannot be used to read the file. However, due to the implementation differences of file systems, some user-mode files opened in 'w' mode can be read by using FD. To perform the read or write operation on a file by using FD, you are advised to open the file in 'rw' mode. The write operations are mutually exclusive. After a write operation is complete, you must call **close** to close the file.
W
wusongqing 已提交
1325

W
wusongqing 已提交
1326
**Required permissions**: ohos.permission.READ_MEDIA or ohos.permission.WRITE_MEDIA
W
wusongqing 已提交
1327 1328 1329 1330 1331

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
1332 1333
| Name     | Type                         | Mandatory  | Description                                 |
| -------- | --------------------------- | ---- | ----------------------------------- |
A
Annie_wang 已提交
1334 1335
| 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 invoked to return the FD of the file opened.                           |
W
wusongqing 已提交
1336 1337 1338

**Example**

1339
```js
W
wusongqing 已提交
1340
async function example() {
A
Annie_wang 已提交
1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351
  let mediaType = mediaLibrary.MediaType.IMAGE;
  let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE;
  const path = await media.getPublicDirectory(DIR_IMAGE);
  const asset = await media.createAsset(mediaType, 'image00003.jpg', path);
  asset.open('rw', (error, fd) => {
    if (fd > 0) {
      asset.close(fd);
    } else {
      console.error('File Open failed with error: ' + error);
    }
  });
W
wusongqing 已提交
1352 1353 1354 1355 1356 1357 1358 1359 1360
}
```

### open<sup>8+</sup>

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

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

A
Annie_wang 已提交
1361 1362 1363
> **NOTE**
> This API is deprecated since API Version 9. Use [open](js-apis-photoAccessHelper.md#open-1) instead.

A
Annie_wang 已提交
1364
**NOTE**<br>If a file is opened in 'w' mode, the returned FD cannot be used to read the file. However, due to the implementation differences of file systems, some user-mode files opened in 'w' mode can be read by using FD. To perform the read or write operation on a file by using FD, you are advised to open the file in 'rw' mode. The write operations are mutually exclusive. After a write operation is complete, you must call **close** to close the file.
W
wusongqing 已提交
1365

W
wusongqing 已提交
1366
**Required permissions**: ohos.permission.READ_MEDIA or ohos.permission.WRITE_MEDIA
W
wusongqing 已提交
1367 1368 1369 1370 1371

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
1372 1373
| Name | Type    | Mandatory  | Description                                 |
| ---- | ------ | ---- | ----------------------------------- |
A
Annie_wang 已提交
1374
| mode | string | Yes   | File open mode, which can be **r** (read-only), **w** (write-only), or **rw** (read-write).|
W
wusongqing 已提交
1375 1376 1377

**Return value**

W
wusongqing 已提交
1378 1379
| Type                   | Description           |
| --------------------- | ------------- |
A
Annie_wang 已提交
1380
| Promise&lt;number&gt; | Promise used to return the FD of the file opened.|
W
wusongqing 已提交
1381 1382 1383

**Example**

1384
```js
W
wusongqing 已提交
1385
async function example() {
A
Annie_wang 已提交
1386 1387 1388 1389 1390 1391 1392 1393 1394
  let mediaType = mediaLibrary.MediaType.IMAGE;
  let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE;
  const path = await media.getPublicDirectory(DIR_IMAGE);
  const asset = await media.createAsset(mediaType, 'image00003.jpg', path);
  asset.open('rw').then((fd) => {
    console.info('File open fd: ' + fd);
  }).catch((error) => {
    console.error('File open failed with error: ' + error);
  });
W
wusongqing 已提交
1395 1396 1397 1398 1399 1400 1401
}
```

### close<sup>8+</sup>

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

A
Annie_wang 已提交
1402
Closes a file. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
1403

A
Annie_wang 已提交
1404 1405 1406
> **NOTE**
> This API is deprecated since API Version 9. Use [close](js-apis-photoAccessHelper.md#close) instead.

W
wusongqing 已提交
1407
**Required permissions**: ohos.permission.READ_MEDIA or ohos.permission.WRITE_MEDIA
W
wusongqing 已提交
1408 1409 1410 1411 1412

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
1413 1414
| Name     | Type                       | Mandatory  | Description   |
| -------- | ------------------------- | ---- | ----- |
A
Annie_wang 已提交
1415 1416
| fd       | number                    | Yes   | FD of the file to close.|
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback that returns no value.|
W
wusongqing 已提交
1417 1418 1419

**Example**

1420
```js
W
wusongqing 已提交
1421
async function example() {
A
Annie_wang 已提交
1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  const fetchFileResult = await media.getFileAssets(getImageOp);
  const asset = await fetchFileResult.getFirstObject();
  asset.open('rw').then((fd) => {
    console.info('File open fd: ' + fd);
    asset.close(fd, (error) => {
      if (error) {
        console.error('asset.close failed with error: ' + error);
      } else {
        console.info('asset.close successfully');
      }
W
wusongqing 已提交
1439
    });
A
Annie_wang 已提交
1440 1441 1442 1443
  }).catch((error) => {
    console.error('File open failed with error: ' + error);
  });
  fetchFileResult.close();
W
wusongqing 已提交
1444 1445 1446 1447 1448 1449 1450
}
```

### close<sup>8+</sup>

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

A
Annie_wang 已提交
1451
Closes a file. This API uses a promise to return the result.
W
wusongqing 已提交
1452

A
Annie_wang 已提交
1453 1454 1455
> **NOTE**
> This API is deprecated since API Version 9. Use [close](js-apis-photoAccessHelper.md#close-1) instead.

W
wusongqing 已提交
1456
**Required permissions**: ohos.permission.READ_MEDIA or ohos.permission.WRITE_MEDIA
W
wusongqing 已提交
1457 1458 1459 1460 1461

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
1462 1463
| Name | Type    | Mandatory  | Description   |
| ---- | ------ | ---- | ----- |
A
Annie_wang 已提交
1464
| fd   | number | Yes   | FD of the file to close.|
W
wusongqing 已提交
1465 1466 1467

**Return value**

W
wusongqing 已提交
1468 1469
| Type                 | Description        |
| ------------------- | ---------- |
A
Annie_wang 已提交
1470
| Promise&lt;void&gt; | Promise that returns no value.|
W
wusongqing 已提交
1471 1472 1473

**Example**

1474
```js
W
wusongqing 已提交
1475
async function example() {
A
Annie_wang 已提交
1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  const fetchFileResult = await media.getFileAssets(getImageOp);
  const asset = await fetchFileResult.getFirstObject();
  asset.open('rw').then((fd) => {
    console.info('File fd!' + fd);
    asset.close(fd).then(() => {
      console.info('asset.close successfully');
    }).catch((closeErr) => {
      console.error('asset.close fail, closeErr: ' + closeErr);
W
wusongqing 已提交
1491
    });
A
Annie_wang 已提交
1492 1493 1494 1495
  }).catch((error) => {
    console.error('open File failed with error: ' + error);
  });
  fetchFileResult.close();
W
wusongqing 已提交
1496 1497 1498 1499 1500 1501 1502 1503 1504
}
```

### getThumbnail<sup>8+</sup>

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.

A
Annie_wang 已提交
1505 1506 1507
> **NOTE**
> This API is deprecated since API Version 9. Use [close](js-apis-photoAccessHelper.md#getThumbnail) instead.

W
wusongqing 已提交
1508 1509 1510 1511 1512 1513
**Required permissions**: ohos.permission.READ_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
1514 1515
| Name     | Type                                 | Mandatory  | Description              |
| -------- | ----------------------------------- | ---- | ---------------- |
A
Annie_wang 已提交
1516
| callback | AsyncCallback&lt;image.PixelMap&gt; | Yes   | Callback invoked to return the PixelMap of the thumbnail.|
W
wusongqing 已提交
1517 1518 1519

**Example**

1520
```js
W
wusongqing 已提交
1521
async function example() {
A
Annie_wang 已提交
1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  const fetchFileResult = await media.getFileAssets(getImageOp);
  const asset = await fetchFileResult.getFirstObject();
  asset.getThumbnail((error, pixelmap) => {
    if (error) {
      console.error('mediaLibrary getThumbnail failed with error: ' + error);
    } else {
      console.info('mediaLibrary getThumbnail Successful, pixelmap ' + JSON.stringify(pixelmap));
    }
  });
  fetchFileResult.close();
W
wusongqing 已提交
1539 1540 1541 1542 1543 1544 1545
}
```

### getThumbnail<sup>8+</sup>

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

A
Annie_wang 已提交
1546
Obtains the file thumbnail of the given size. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
1547

A
Annie_wang 已提交
1548 1549 1550
> **NOTE**
> This API is deprecated since API Version 9. Use [close](js-apis-photoAccessHelper.md#getThumbnail-1) instead.

W
wusongqing 已提交
1551 1552 1553 1554 1555 1556
**Required permissions**: ohos.permission.READ_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
1557 1558 1559
| Name     | Type                                 | Mandatory  | Description              |
| -------- | ----------------------------------- | ---- | ---------------- |
| size     | [Size](#size8)                      | Yes   | Size of the thumbnail.           |
A
Annie_wang 已提交
1560
| callback | AsyncCallback&lt;image.PixelMap&gt; | Yes   | Callback invoked to return the PixelMap of the thumbnail.|
W
wusongqing 已提交
1561 1562 1563

**Example**

1564
```js
W
wusongqing 已提交
1565
async function example() {
A
Annie_wang 已提交
1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  let size = { width: 720, height: 720 };
  const fetchFileResult = await media.getFileAssets(getImageOp);
  const asset = await fetchFileResult.getFirstObject();
  asset.getThumbnail(size, (error, pixelmap) => {
    if (error) {
      console.error('mediaLibrary getThumbnail failed with error: ' + error);
    } else {
      console.info('mediaLibrary getThumbnail Successful, pixelmap ' + JSON.stringify(pixelmap));
    }
  });
  fetchFileResult.close();
W
wusongqing 已提交
1584 1585 1586 1587 1588 1589 1590
}
```

### getThumbnail<sup>8+</sup>

getThumbnail(size?: Size): Promise&lt;image.PixelMap&gt;

A
Annie_wang 已提交
1591
Obtains the file thumbnail of the given size. This API uses a promise to return the result.
W
wusongqing 已提交
1592

A
Annie_wang 已提交
1593 1594 1595
> **NOTE**
> This API is deprecated since API Version 9. Use [close](js-apis-photoAccessHelper.md#getThumbnail-2) instead.

W
wusongqing 已提交
1596 1597 1598 1599 1600 1601
**Required permissions**: ohos.permission.READ_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
1602 1603 1604
| Name | Type            | Mandatory  | Description   |
| ---- | -------------- | ---- | ----- |
| size | [Size](#size8) | No   | Size of the thumbnail.|
W
wusongqing 已提交
1605 1606 1607

**Return value**

W
wusongqing 已提交
1608 1609
| Type                           | Description                   |
| ----------------------------- | --------------------- |
A
Annie_wang 已提交
1610
| Promise&lt;image.PixelMap&gt; | Promise used to return the PixelMap of the thumbnail.|
W
wusongqing 已提交
1611 1612 1613

**Example**

1614
```js
W
wusongqing 已提交
1615
async function example() {
A
Annie_wang 已提交
1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  let size = { width: 720, height: 720 };
  const fetchFileResult = await media.getFileAssets(getImageOp);
  const asset = await fetchFileResult.getFirstObject();
  asset.getThumbnail(size).then((pixelmap) => {
    console.info('mediaLibrary getThumbnail Successful, pixelmap ' + JSON.stringify(pixelmap));
  }).catch((error) => {
    console.error('mediaLibrary getThumbnail failed with error: ' + error);
  });
  fetchFileResult.close();
W
wusongqing 已提交
1632 1633 1634 1635 1636 1637 1638 1639 1640
}
```

### favorite<sup>8+</sup>

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.

A
Annie_wang 已提交
1641 1642 1643
> **NOTE**
> This API is deprecated since API Version 9. Use [setFavorite](js-apis-photoAccessHelper.md#setfavorite) instead.

W
wusongqing 已提交
1644 1645 1646 1647 1648 1649
**Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
1650 1651
| Name       | Type                       | Mandatory  | Description                                |
| ---------- | ------------------------- | ---- | ---------------------------------- |
A
Annie_wang 已提交
1652 1653
| 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.                             |
W
wusongqing 已提交
1654 1655 1656

**Example**

1657
```js
W
wusongqing 已提交
1658
async function example() {
A
Annie_wang 已提交
1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  const fetchFileResult = await media.getFileAssets(getImageOp);
  const asset = await fetchFileResult.getFirstObject();
  asset.favorite(true,(error) => {
    if (error) {
      console.error('mediaLibrary favorite failed with error: ' + error);
    } else {
      console.info('mediaLibrary favorite Successful');
    }
  });
  fetchFileResult.close();
W
wusongqing 已提交
1676 1677 1678 1679 1680 1681 1682 1683 1684
}
```

### favorite<sup>8+</sup>

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

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

A
Annie_wang 已提交
1685 1686 1687
> **NOTE**
> This API is deprecated since API Version 9. Use [setFavorite](js-apis-photoAccessHelper.md#setfavorite-1) instead.

W
wusongqing 已提交
1688 1689 1690 1691 1692 1693
**Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
1694 1695
| Name       | Type     | Mandatory  | Description                                |
| ---------- | ------- | ---- | ---------------------------------- |
A
Annie_wang 已提交
1696
| isFavorite | boolean | Yes   | Operation to perform. The value **true** means to favorite the file asset, and **false** means the opposite.|
W
wusongqing 已提交
1697 1698 1699

**Return value**

W
wusongqing 已提交
1700 1701
| Type                 | Description        |
| ------------------- | ---------- |
A
Annie_wang 已提交
1702
| Promise&lt;void&gt; | Promise that returns no value.|
W
wusongqing 已提交
1703 1704 1705

**Example**

1706
```js
W
wusongqing 已提交
1707
async function example() {
A
Annie_wang 已提交
1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  const fetchFileResult = await media.getFileAssets(getImageOp);
  const asset = await fetchFileResult.getFirstObject();
  asset.favorite(true).then(() => {
    console.info('mediaLibrary favorite Successful');
  }).catch((error) => {
    console.error('mediaLibrary favorite failed with error: ' + error);
  });
  fetchFileResult.close();
W
wusongqing 已提交
1723 1724 1725 1726 1727 1728 1729 1730 1731
}
```

### isFavorite<sup>8+</sup>

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

Checks whether this file asset is favorited. This API uses an asynchronous callback to return the result.

A
Annie_wang 已提交
1732 1733 1734
> **NOTE**
> This API is deprecated since API Version 9. There is no substitute API.

W
wusongqing 已提交
1735 1736 1737 1738 1739 1740
**Required permissions**: ohos.permission.READ_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
1741 1742
| Name     | Type                          | Mandatory  | Description         |
| -------- | ---------------------------- | ---- | ----------- |
A
Annie_wang 已提交
1743
| callback | AsyncCallback&lt;boolean&gt; | Yes   | Callback invoked to return the result. The value **true** means the file asset is favorited; the value **false** means the opposite.|
W
wusongqing 已提交
1744 1745 1746

**Example**

1747
```js
W
wusongqing 已提交
1748
async function example() {
A
Annie_wang 已提交
1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  const fetchFileResult = await media.getFileAssets(getImageOp);
  const asset = await fetchFileResult.getFirstObject();
  asset.isFavorite((error, isFavorite) => {
    if (error) {
      console.error('mediaLibrary favoriisFavoritete failed with error: ' + error);
    } else {
      console.info('mediaLibrary isFavorite Successful, isFavorite result: ' + isFavorite);
    }
  });
  fetchFileResult.close();
W
wusongqing 已提交
1766 1767 1768 1769 1770 1771 1772 1773 1774
}
```

### isFavorite<sup>8+</sup>

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

Checks whether this file asset is favorited. This API uses a promise to return the result.

A
Annie_wang 已提交
1775 1776 1777
> **NOTE**
> This API is deprecated since API Version 9. There is no substitute API.

W
wusongqing 已提交
1778 1779 1780 1781 1782 1783
**Required permissions**: ohos.permission.READ_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Return value**

W
wusongqing 已提交
1784 1785
| Type                    | Description                |
| ---------------------- | ------------------ |
A
Annie_wang 已提交
1786
| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means the file asset is favorited; the value **false** means the opposite.|
W
wusongqing 已提交
1787 1788 1789

**Example**

1790
```js
W
wusongqing 已提交
1791
async function example() {
A
Annie_wang 已提交
1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  const fetchFileResult = await media.getFileAssets(getImageOp);
  const asset = await fetchFileResult.getFirstObject();
  asset.isFavorite().then((isFavorite) => {
    console.info('mediaLibrary isFavorite Successful, isFavorite result: ' + isFavorite);
  }).catch((error) => {
    console.error('mediaLibrary favoriisFavoritete failed with error: ' + error);
  });
  fetchFileResult.close();
W
wusongqing 已提交
1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817
}
```

### trash<sup>8+</sup>

trash(isTrash: boolean, callback: AsyncCallback&lt;void&gt;): void

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

Files in the trash are not actually deleted. You can set **isTrash** to **false** to restore the files from the trash.

A
Annie_wang 已提交
1818 1819 1820
> **NOTE**
> This API is deprecated since API Version 9. Use [deleteAssets](js-apis-photoAccessHelper.md#deleteAssets) instead.

W
wusongqing 已提交
1821 1822 1823 1824 1825 1826
**Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
1827 1828
| Name     | Type                       | Mandatory  | Description       |
| -------- | ------------------------- | ---- | --------- |
A
Annie_wang 已提交
1829 1830
| isTrash  | boolean                   | Yes   | Whether to move the file asset to the trash.|
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback that returns no value.    |
W
wusongqing 已提交
1831 1832 1833

**Example**

1834
```js
W
wusongqing 已提交
1835
async function example() {
A
Annie_wang 已提交
1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  const fetchFileResult = await media.getFileAssets(getImageOp);
  const asset = await fetchFileResult.getFirstObject();
  asset.trash(true, (error) => {
    if (error) {
      console.error('mediaLibrary trash failed with error: ' + error);
    } else {
      console.info('mediaLibrary trash Successful');
    }
  });
  fetchFileResult.close();
W
wusongqing 已提交
1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863
}
```

### trash<sup>8+</sup>

trash(isTrash: boolean): Promise&lt;void&gt;

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

Files in the trash are not actually deleted. You can set **isTrash** to **false** to restore the files from the trash.

A
Annie_wang 已提交
1864 1865 1866
> **NOTE**
> This API is deprecated since API Version 9. Use [deleteAssets](js-apis-photoAccessHelper.md#deleteAssets-1) instead.

W
wusongqing 已提交
1867 1868 1869 1870 1871 1872
**Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
1873 1874
| Name    | Type     | Mandatory  | Description       |
| ------- | ------- | ---- | --------- |
A
Annie_wang 已提交
1875
| isTrash | boolean | Yes   | Whether to move the file asset to the trash.|
W
wusongqing 已提交
1876 1877 1878

**Return value**

W
wusongqing 已提交
1879 1880
| Type                 | Description        |
| ------------------- | ---------- |
A
Annie_wang 已提交
1881
| Promise&lt;void&gt; | Promise that returns no value.|
W
wusongqing 已提交
1882 1883 1884

**Example**

1885
```js
W
wusongqing 已提交
1886
async function example() {
A
Annie_wang 已提交
1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  const fetchFileResult = await media.getFileAssets(getImageOp);
  const asset = await fetchFileResult.getFirstObject();
  asset.trash(true).then(() => {
    console.info('trash successfully');
  }).catch((error) => {
    console.error('trash failed with error: ' + error);
  });
  fetchFileResult.close();
W
wusongqing 已提交
1902 1903 1904 1905 1906 1907 1908 1909 1910
}
```

### isTrash<sup>8+</sup>

isTrash(callback: AsyncCallback&lt;boolean&gt;): void

Checks whether this file asset is in the trash. This API uses an asynchronous callback to return the result.

A
Annie_wang 已提交
1911 1912 1913
> **NOTE**
> This API is deprecated since API Version 9. There is no substitute API.

W
wusongqing 已提交
1914 1915 1916 1917 1918 1919
**Required permissions**: ohos.permission.READ_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
1920 1921
| Name     | Type                          | Mandatory  | Description             |
| -------- | ---------------------------- | ---- | --------------- |
A
Annie_wang 已提交
1922
| callback | AsyncCallback&lt;boolean&gt; | Yes   | Callback invoked to return the result. The value **true** means the file is in the trash; the value **false** means the opposite.|
W
wusongqing 已提交
1923 1924 1925

**Example**

1926
```js
W
wusongqing 已提交
1927
async function example() {
A
Annie_wang 已提交
1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  const fetchFileResult = await media.getFileAssets(getImageOp);
  const asset = await fetchFileResult.getFirstObject();
  asset.isTrash((error, isTrash) => {
    if (error) {
      console.error('Failed to get trash state failed with error: ' + error);
      return;
    }
    console.info('Get trash state successfully, isTrash result: ' + isTrash);
  });
  fetchFileResult.close();
W
wusongqing 已提交
1945 1946 1947 1948 1949 1950 1951 1952 1953
}
```

### isTrash<sup>8+</sup>

isTrash():Promise&lt;boolean&gt;

Checks whether this file asset is in the trash. This API uses a promise to return the result.

A
Annie_wang 已提交
1954 1955 1956
> **NOTE**
> This API is deprecated since API Version 9. There is no substitute API.

W
wusongqing 已提交
1957 1958 1959 1960 1961 1962
**Required permissions**: ohos.permission.READ_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Return value**

W
wusongqing 已提交
1963 1964
| Type                 | Description                  |
| ------------------- | -------------------- |
A
Annie_wang 已提交
1965
| Promise&lt;void&gt; | Promise used to return the result. The value **true** means the file is in the trash; the value **false** means the opposite.|
W
wusongqing 已提交
1966 1967 1968

**Example**

1969
```js
W
wusongqing 已提交
1970
async function example() {
A
Annie_wang 已提交
1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  const fetchFileResult = await media.getFileAssets(getImageOp);
  const asset = await fetchFileResult.getFirstObject();
  asset.isTrash().then((isTrash) => {
    console.info('isTrash result: ' + isTrash);
  }).catch((error) => {
    console.error('isTrash failed with error: ' + error);
  });
  fetchFileResult.close();
W
wusongqing 已提交
1986 1987 1988
}
```

W
wusongqing 已提交
1989
## FetchFileResult<sup>7+</sup>
W
wusongqing 已提交
1990

A
Annie_wang 已提交
1991
Provides APIs to manage the file retrieval result.
W
wusongqing 已提交
1992

A
Annie_wang 已提交
1993 1994 1995
> **NOTE**
> This API is deprecated since API Version 9. Use [FetchResult](js-apis-photoAccessHelper.md#fetchresult) instead.

W
wusongqing 已提交
1996
### getCount<sup>7+</sup>
W
wusongqing 已提交
1997 1998 1999 2000 2001

getCount(): number

Obtains the total number of files in the result set.

A
Annie_wang 已提交
2002 2003 2004
> **NOTE**
> This API is deprecated since API Version 9. Use [getCount](js-apis-photoAccessHelper.md#getcount) instead.

W
wusongqing 已提交
2005 2006 2007 2008
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Return value**

W
wusongqing 已提交
2009 2010
| Type    | Description      |
| ------ | -------- |
A
Annie_wang 已提交
2011
| number | Returns the total number of files obtained.|
W
wusongqing 已提交
2012 2013 2014

**Example**

2015
```js
W
wusongqing 已提交
2016
async function example() {
A
Annie_wang 已提交
2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027
  let fileKeyObj = mediaLibrary.FileKey;
  let fileType = mediaLibrary.MediaType.FILE;
  let getFileCountOneOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [fileType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  let fetchFileResult = await media.getFileAssets(getFileCountOneOp);
  const fetchCount = fetchFileResult.getCount();
  console.info('fetchCount result: ' + fetchCount);
  fetchFileResult.close();
W
wusongqing 已提交
2028 2029 2030
}
```

W
wusongqing 已提交
2031
### isAfterLast<sup>7+</sup>
W
wusongqing 已提交
2032 2033 2034 2035 2036

isAfterLast(): boolean

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

A
Annie_wang 已提交
2037 2038 2039
> **NOTE**
> This API is deprecated since API Version 9. Use [isAfterLast](js-apis-photoAccessHelper.md#isafterlast) instead.

W
wusongqing 已提交
2040 2041 2042 2043
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Return value**

W
wusongqing 已提交
2044 2045
| Type     | Description                                |
| ------- | ---------------------------------- |
A
Annie_wang 已提交
2046
| boolean | Returns **true** if the cursor is in the last row of the result set; returns **false** otherwise.|
W
wusongqing 已提交
2047 2048 2049

**Example**

2050
```js
W
wusongqing 已提交
2051
async function example() {
A
Annie_wang 已提交
2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  let fetchFileResult = await media.getFileAssets(getImageOp);
  const fetchCount = fetchFileResult.getCount();
  console.info('mediaLibrary fetchFileResult.getCount, count:' + fetchCount);
  let fileAsset = await fetchFileResult.getFirstObject();
  for (var i = 1; i < fetchCount; i++) {
    fileAsset = await fetchFileResult.getNextObject();
    if(i == fetchCount - 1) {
      var result = fetchFileResult.isAfterLast();
      console.info('mediaLibrary fileAsset isAfterLast result: ' + result);
      fetchFileResult.close();
W
wusongqing 已提交
2069
    }
A
Annie_wang 已提交
2070
  }
W
wusongqing 已提交
2071 2072 2073
}
```

W
wusongqing 已提交
2074
### close<sup>7+</sup>
W
wusongqing 已提交
2075 2076 2077

close(): void

A
Annie_wang 已提交
2078
Releases and invalidates this **FetchFileResult** instance. After this instance is released, the APIs in this instance cannot be invoked.
W
wusongqing 已提交
2079

A
Annie_wang 已提交
2080 2081 2082
> **NOTE**
> This API is deprecated since API Version 9. Use [close](js-apis-photoAccessHelper.md#close) instead.

W
wusongqing 已提交
2083 2084 2085 2086
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Example**

2087
```js
W
wusongqing 已提交
2088
async function example() {
A
Annie_wang 已提交
2089 2090 2091 2092 2093 2094 2095 2096 2097
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  let fetchFileResult = await media.getFileAssets(getImageOp);
  fetchFileResult.close();
W
wusongqing 已提交
2098 2099 2100
}
```

W
wusongqing 已提交
2101
### getFirstObject<sup>7+</sup>
W
wusongqing 已提交
2102 2103 2104 2105 2106

getFirstObject(callback: AsyncCallback&lt;FileAsset&gt;): void

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

A
Annie_wang 已提交
2107 2108 2109
> **NOTE**
> This API is deprecated since API Version 9. Use [getFirstObject](js-apis-photoAccessHelper.md#getfirstobject) instead.

W
wusongqing 已提交
2110 2111 2112 2113
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
2114 2115
| Name  | Type                                         | Mandatory| Description                                       |
| -------- | --------------------------------------------- | ---- | ------------------------------------------- |
A
Annie_wang 已提交
2116
| callback | AsyncCallback&lt;[FileAsset](#fileasset7)&gt; | Yes  | Callback invoked to return the first **FileAsset** object in the result set.|
W
wusongqing 已提交
2117 2118 2119

**Example**

2120
```js
W
wusongqing 已提交
2121
async function example() {
A
Annie_wang 已提交
2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  let fetchFileResult = await media.getFileAssets(getImageOp);
  fetchFileResult.getFirstObject((error, fileAsset) => {
    if (error) {
      console.error('fetchFileResult getFirstObject failed with error: ' + error);
      return;
    }
    console.info('getFirstObject successfully, displayName : ' + fileAsset.displayName);
    fetchFileResult.close();
  })
W
wusongqing 已提交
2138 2139 2140
}
```

W
wusongqing 已提交
2141
### getFirstObject<sup>7+</sup>
W
wusongqing 已提交
2142 2143 2144 2145 2146

getFirstObject(): Promise&lt;FileAsset&gt;

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

A
Annie_wang 已提交
2147 2148 2149
> **NOTE**
> This API is deprecated since API Version 9. Use [getFirstObject](js-apis-photoAccessHelper.md#getfirstobject-1) instead.

W
wusongqing 已提交
2150 2151 2152 2153
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Return value**

W
wusongqing 已提交
2154 2155
| Type                                   | Description                      |
| --------------------------------------- | -------------------------- |
A
Annie_wang 已提交
2156
| Promise&lt;[FileAsset](#fileasset7)&gt; | Promise used to return the first **FileAsset** object in the result set.|
W
wusongqing 已提交
2157 2158 2159

**Example**

2160
```js
W
wusongqing 已提交
2161
async function example() {
A
Annie_wang 已提交
2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  let fetchFileResult = await media.getFileAssets(getImageOp);
  fetchFileResult.getFirstObject().then((fileAsset) => {
    console.info('getFirstObject successfully, displayName: ' + fileAsset.displayName);
    fetchFileResult.close();
  }).catch((error) => {
    console.error('getFirstObject failed with error: ' + error);
  });
W
wusongqing 已提交
2176 2177 2178
}
```

W
wusongqing 已提交
2179
### getNextObject<sup>7+</sup>
W
wusongqing 已提交
2180

2181
getNextObject(callback: AsyncCallback&lt;FileAsset&gt;): void
W
wusongqing 已提交
2182 2183

Obtains the next file asset in the result set. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
2184

A
Annie_wang 已提交
2185 2186 2187 2188
> **NOTE**
>
> - Before using this API, you must use [getFirstObject](#getfirstobject7) to obtain the first file asset and then use [isAfterLast](#isafterlast7) to check that the cursor does not point to the last file asset in the result set.
> - This API is deprecated since API Version 9. Use [getNextObject](js-apis-photoAccessHelper.md#getnextobject) instead.
W
wusongqing 已提交
2189 2190 2191 2192 2193

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
2194 2195
| Name   | Type                                         | Mandatory| Description                                     |
| --------- | --------------------------------------------- | ---- | ----------------------------------------- |
A
Annie_wang 已提交
2196
| callbacke | AsyncCallback&lt;[FileAsset](#fileasset7)&gt; | Yes  | Callback invoked to return the next **FileAsset** object in the result set.|
W
wusongqing 已提交
2197 2198 2199

**Example**

2200
```js
W
wusongqing 已提交
2201
async function example() {
A
Annie_wang 已提交
2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  let fetchFileResult = await media.getFileAssets(getImageOp);
  let fileAsset = await fetchFileResult.getFirstObject();
  console.log('fetchFileResult getFirstObject successfully, displayName: ' + fileAsset.displayName);
  if (!fetchFileResult.isAfterLast()) {
    fetchFileResult.getNextObject((error, fileAsset) => {
      if (error) {
        console.error('fetchFileResult getNextObject failed with error: ' + error);
        return;
      }
      console.log('fetchFileResult getNextObject successfully, displayName: ' + fileAsset.displayName);
      fetchFileResult.close();
    })
  }
W
wusongqing 已提交
2222
}
G
Gloria 已提交
2223

W
wusongqing 已提交
2224 2225
```

W
wusongqing 已提交
2226
### getNextObject<sup>7+</sup>
W
wusongqing 已提交
2227

2228
getNextObject(): Promise&lt;FileAsset&gt;
W
wusongqing 已提交
2229 2230

Obtains the next file asset in the result set. This API uses a promise to return the result.
A
Annie_wang 已提交
2231

A
Annie_wang 已提交
2232 2233 2234 2235
> **NOTE**
>
> - Before using this API, you must use [getFirstObject](#getfirstobject7) to obtain the first file asset and then use [isAfterLast](#isafterlast7) to check that the cursor does not point to the last file asset in the result set.
> - This API is deprecated since API Version 9. Use [getNextObject](js-apis-photoAccessHelper.md#getnextobject-1) instead.
W
wusongqing 已提交
2236 2237 2238 2239 2240

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Return value**

W
wusongqing 已提交
2241 2242
| Type                                   | Description             |
| --------------------------------------- | ----------------- |
A
Annie_wang 已提交
2243
| Promise&lt;[FileAsset](#fileasset7)&gt; | Promise used to return the next **FileAsset** object in the result set.|
W
wusongqing 已提交
2244 2245 2246

**Example**

2247
```js
W
wusongqing 已提交
2248
async function example() {
A
Annie_wang 已提交
2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  let fetchFileResult = await media.getFileAssets(getImageOp);
  let fileAsset = await fetchFileResult.getFirstObject();
  console.log('fetchFileResult getFirstObject successfully, displayName: ' + fileAsset.displayName);
  if (!fetchFileResult.isAfterLast()) {
    fetchFileResult.getNextObject().then((fileAsset) => {
      console.info('fetchFileResult getNextObject successfully, displayName: ' + fileAsset.displayName);
      fetchFileResult.close();
    }).catch((error) => {
      console.error('fetchFileResult getNextObject failed with error: ' + error);
    })
  }
W
wusongqing 已提交
2267 2268 2269
}
```

W
wusongqing 已提交
2270
### getLastObject<sup>7+</sup>
W
wusongqing 已提交
2271 2272 2273 2274 2275

getLastObject(callback: AsyncCallback&lt;FileAsset&gt;): void

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

A
Annie_wang 已提交
2276 2277 2278
> **NOTE**
> This API is deprecated since API Version 9. Use [getLastObject](js-apis-photoAccessHelper.md#getlastobject) instead.

W
wusongqing 已提交
2279 2280 2281 2282
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
2283 2284
| Name  | Type                                         | Mandatory| Description                       |
| -------- | --------------------------------------------- | ---- | --------------------------- |
A
Annie_wang 已提交
2285
| callback | AsyncCallback&lt;[FileAsset](#fileasset7)&gt; | Yes  | Callback invoked to return the last **FileAsset** object in the result set.|
W
wusongqing 已提交
2286 2287 2288

**Example**

2289
```js
W
wusongqing 已提交
2290
async function example() {
A
Annie_wang 已提交
2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  let fetchFileResult = await media.getFileAssets(getImageOp);
  fetchFileResult.getLastObject((error, fileAsset) => {
    if (error) {
      console.error('getLastObject failed with error: ' + error);
      return;
    }
    console.info('getLastObject successfully, displayName: ' + fileAsset.displayName);
    fetchFileResult.close();
  })
W
wusongqing 已提交
2307 2308 2309
}
```

W
wusongqing 已提交
2310
### getLastObject<sup>7+</sup>
W
wusongqing 已提交
2311 2312 2313 2314 2315

getLastObject(): Promise&lt;FileAsset&gt;

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

A
Annie_wang 已提交
2316 2317 2318
> **NOTE**
> This API is deprecated since API Version 9. Use [getLastObject](js-apis-photoAccessHelper.md#getlastobject-1) instead.

W
wusongqing 已提交
2319 2320 2321 2322
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Return value**

W
wusongqing 已提交
2323 2324
| Type                                   | Description             |
| --------------------------------------- | ----------------- |
A
Annie_wang 已提交
2325
| Promise&lt;[FileAsset](#fileasset7)&gt; | Promise used to return the last **FileAsset** object in the result set.|
W
wusongqing 已提交
2326 2327 2328

**Example**

2329
```js
W
wusongqing 已提交
2330
async function example() {
A
Annie_wang 已提交
2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  let fetchFileResult = await media.getFileAssets(getImageOp);
  fetchFileResult.getLastObject().then((fileAsset) => {
    console.info('getLastObject successfully, displayName: ' + fileAsset.displayName);
    fetchFileResult.close();
  }).catch((error) => {
    console.error('getLastObject failed with error: ' + error);
  });
W
wusongqing 已提交
2345 2346 2347
}
```

W
wusongqing 已提交
2348
### getPositionObject<sup>7+</sup>
W
wusongqing 已提交
2349 2350 2351 2352 2353

getPositionObject(index: number, callback: AsyncCallback&lt;FileAsset&gt;): void

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

A
Annie_wang 已提交
2354 2355 2356
> **NOTE**
> This API is deprecated since API Version 9. Use [getObjectByPosition](js-apis-photoAccessHelper.md#getobjectbyposition) instead.

W
wusongqing 已提交
2357 2358 2359 2360
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
2361 2362
| Name      | Type                                      | Mandatory  | Description                |
| -------- | ---------------------------------------- | ---- | ------------------ |
G
Gloria 已提交
2363
| index    | number                                   | Yes   | Index of the file to obtain. The value starts from 0 and must be smaller than the **count** value of the result set.    |
A
Annie_wang 已提交
2364
| callback | AsyncCallback&lt;[FileAsset](#fileasset7)&gt; | Yes   | Callback invoked to return the **FileAsset** object with the specified index obtained.|
W
wusongqing 已提交
2365 2366 2367

**Example**

2368
```js
W
wusongqing 已提交
2369
async function example() {
A
Annie_wang 已提交
2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  let fetchFileResult = await media.getFileAssets(getImageOp);
  fetchFileResult.getPositionObject(0, (error, fileAsset) => {
    if (error) {
      console.error('getPositionObject failed with error: ' + error);
      return;
    }
    console.info('getPositionObject successfully, displayName: ' + fileAsset.displayName);
    fetchFileResult.close();
  })
W
wusongqing 已提交
2386 2387 2388
}
```

W
wusongqing 已提交
2389
### getPositionObject<sup>7+</sup>
W
wusongqing 已提交
2390 2391 2392 2393 2394

getPositionObject(index: number): Promise&lt;FileAsset&gt;

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

A
Annie_wang 已提交
2395 2396 2397
> **NOTE**
> This API is deprecated since API Version 9. Use [getObjectByPosition](js-apis-photoAccessHelper.md#getobjectbyposition-1) instead.

W
wusongqing 已提交
2398 2399 2400 2401
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
2402 2403
| Name   | Type    | Mandatory  | Description            |
| ----- | ------ | ---- | -------------- |
G
Gloria 已提交
2404
| index | number | Yes   | Index of the file to obtain. The value starts from 0 and must be smaller than the **count** value of the result set.|
W
wusongqing 已提交
2405 2406 2407

**Return value**

W
wusongqing 已提交
2408 2409
| Type                                   | Description             |
| --------------------------------------- | ----------------- |
A
Annie_wang 已提交
2410
| Promise&lt;[FileAsset](#fileasset7)&gt; | Promise used to return the **FileAsset** object with the specified index obtained.|
W
wusongqing 已提交
2411 2412 2413

**Example**

2414
```js
W
wusongqing 已提交
2415
async function example() {
A
Annie_wang 已提交
2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  let fetchFileResult = await media.getFileAssets(getImageOp);
  fetchFileResult.getPositionObject(0).then((fileAsset) => {
    console.info('getPositionObject successfully, displayName: ' + fileAsset.displayName);
    fetchFileResult.close();
  }).catch((error) => {
    console.error('getPositionObject failed with error: ' + error);
  });
W
wusongqing 已提交
2430 2431 2432
}
```

W
wusongqing 已提交
2433
### getAllObject<sup>7+</sup>
W
wusongqing 已提交
2434 2435 2436 2437 2438

getAllObject(callback: AsyncCallback&lt;Array&lt;FileAsset&gt;&gt;): void

Obtains all the file assets in the result set. This API uses an asynchronous callback to return the result.

A
Annie_wang 已提交
2439 2440 2441
> **NOTE**
> This API is deprecated since API Version 9. Use [getAllObjects](js-apis-photoAccessHelper.md#getallobjects) instead.

W
wusongqing 已提交
2442 2443 2444 2445
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
2446 2447
| Name      | Type                                      | Mandatory  | Description                  |
| -------- | ---------------------------------------- | ---- | -------------------- |
A
Annie_wang 已提交
2448
| callback | AsyncCallback&lt;Array&lt;[FileAsset](#fileasset7)&gt;&gt; | Yes   | Callback invoked to return all the **FileAsset** objects in the result reset.|
W
wusongqing 已提交
2449 2450 2451

**Example**

2452
```js
W
wusongqing 已提交
2453
async function example() {
A
Annie_wang 已提交
2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  let fetchFileResult = await media.getFileAssets(getImageOp);
  fetchFileResult.getAllObject((error, fileAssetList) => {
    if (error) {
      console.error('getAllObject failed with error: ' + error);
      return;
    }
    for (let i = 0; i < fetchFileResult.getCount(); i++) {
      console.info('getAllObject fileAssetList ' + i + ' displayName: ' + fileAssetList[i].displayName);
    }
    fetchFileResult.close();
  })
W
wusongqing 已提交
2472 2473 2474
}
```

W
wusongqing 已提交
2475
### getAllObject<sup>7+</sup>
W
wusongqing 已提交
2476 2477 2478 2479 2480

getAllObject(): Promise&lt;Array&lt;FileAsset&gt;&gt;

Obtains all the file assets in the result set. This API uses a promise to return the result.

A
Annie_wang 已提交
2481 2482 2483
> **NOTE**
> This API is deprecated since API Version 9. Use [getAllObjects](js-apis-photoAccessHelper.md#getallobjects-1) instead.

W
wusongqing 已提交
2484 2485 2486 2487
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Return value**

W
wusongqing 已提交
2488 2489
| Type                                    | Description                 |
| ---------------------------------------- | --------------------- |
A
Annie_wang 已提交
2490
| Promise&lt;Array&lt;[FileAsset](#fileasset7)&gt;&gt; | Promise used to return all the **FileAsset** objects in the result reset.|
W
wusongqing 已提交
2491 2492 2493

**Example**

2494
```js
W
wusongqing 已提交
2495
async function example() {
A
Annie_wang 已提交
2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511
  let fileKeyObj = mediaLibrary.FileKey;
  let imageType = mediaLibrary.MediaType.IMAGE;
  let getImageOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
    order: fileKeyObj.DATE_ADDED + ' DESC',
  };
  let fetchFileResult = await media.getFileAssets(getImageOp);
  fetchFileResult.getAllObject().then((fileAssetList) => {
    for (let i = 0; i < fetchFileResult.getCount(); i++) {
      console.info('getAllObject fileAssetList ' + i + ' displayName: ' + fileAssetList[i].displayName);
    } 
    fetchFileResult.close();
  }).catch((error) => {
    console.error('getAllObject failed with error: ' + error);
  });
W
wusongqing 已提交
2512 2513 2514
}
```

W
wusongqing 已提交
2515
## Album<sup>7+</sup>
W
wusongqing 已提交
2516

A
Annie_wang 已提交
2517
Provides APIs to manage albums.
W
wusongqing 已提交
2518

A
Annie_wang 已提交
2519 2520 2521
> **NOTE**
> This API is deprecated since API Version 9. Use [Album](js-apis-photoAccessHelper.md#album) instead.

W
wusongqing 已提交
2522
### Attributes
W
wusongqing 已提交
2523 2524 2525

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

W
wusongqing 已提交
2526 2527
| Name          | Type   | Readable  | Writable  | Description     |
| ------------ | ------ | ---- | ---- | ------- |
W
wusongqing 已提交
2528
| albumId | number | Yes   | No   | Album ID.   |
A
Annie_wang 已提交
2529 2530 2531
| albumName | string | Yes   | Yes   | Name of the album.   |
| albumUri<sup>8+</sup> | string | Yes   | No   | URI of the album.  |
| dateModified | number | Yes   | No   | Date when the album was last modified.   |
W
wusongqing 已提交
2532 2533 2534
| count<sup>8+</sup> | number | Yes   | No   | Number of files in the album.|
| relativePath<sup>8+</sup> | string | Yes   | No   | Relative path of the album.   |
| coverUri<sup>8+</sup> | string | Yes   | No   | URI of the cover file of the album.|
W
wusongqing 已提交
2535 2536 2537 2538 2539

### commitModify<sup>8+</sup>

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

A
Annie_wang 已提交
2540
Commits the modification on the album attributes to the database.
W
wusongqing 已提交
2541

A
Annie_wang 已提交
2542 2543 2544
> **NOTE**
> This API is deprecated since API Version 9. Use [commitModify](js-apis-photoAccessHelper.md#commitmodify-2) instead.

W
wusongqing 已提交
2545 2546 2547 2548 2549 2550
**Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
2551 2552
| Name  | Type                     | Mandatory| Description      |
| -------- | ------------------------- | ---- | ---------- |
A
Annie_wang 已提交
2553
| callback | AsyncCallback&lt;void&gt; | Yes  | Callback that returns no value.|
W
wusongqing 已提交
2554 2555 2556

**Example**

2557
```js
W
wusongqing 已提交
2558
async function example() {
2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572
  // To obtain the file assets in an album, you must preset the album and resources. The sample code below presets 'New Album 1'.
  let AlbumNoArgsfetchOp = {
    selections: mediaLibrary.FileKey.ALBUM_NAME + '= ?',
    selectionArgs:['New Album 1'],
  };
  const albumList = await media.getAlbums(AlbumNoArgsfetchOp);
  const album = albumList[0];
  album.albumName = 'hello';
  album.commitModify((error) => {
    if (error) {
      console.error('commitModify failed with error: ' + error);
      return;
    }
    console.info('commitModify successful.');
A
Annie_wang 已提交
2573
  });
W
wusongqing 已提交
2574 2575 2576 2577 2578 2579 2580
}
```

### commitModify<sup>8+</sup>

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

A
Annie_wang 已提交
2581
Commits the modification on the album attributes to the database.
W
wusongqing 已提交
2582

A
Annie_wang 已提交
2583 2584 2585
> **NOTE**
> This API is deprecated since API Version 9. Use [commitModify](js-apis-photoAccessHelper.md#commitmodify-3) instead.

W
wusongqing 已提交
2586 2587 2588 2589 2590 2591
**Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Return value**

W
wusongqing 已提交
2592 2593
| Type                 | Description          |
| ------------------- | ------------ |
A
Annie_wang 已提交
2594
| Promise&lt;void&gt; | Promise that returns no value.|
W
wusongqing 已提交
2595 2596 2597

**Example**

2598
```js
W
wusongqing 已提交
2599
async function example() {
2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621
  // To obtain the file assets in an album, you must preset the album and resources. The sample code below presets 'New Album 1'.
  let AlbumNoArgsfetchOp = {
    selections: mediaLibrary.FileKey.ALBUM_NAME + '= ?',
    selectionArgs:['New Album 1'],
  };
  const albumList = await media.getAlbums(AlbumNoArgsfetchOp);
  const album = albumList[0];
  album.albumName = 'hello';
  album.commitModify().then(() => {
    console.info('commitModify successfully');
  }).catch((error) => {
    console.error('commitModify failed with error: ' + error);
  });
}
```

### getFileAssets<sup>7+</sup>

getFileAssets(callback: AsyncCallback&lt;FetchFileResult&gt;): void

Obtains the file assets in this album. This API uses an asynchronous callback to return the result.

A
Annie_wang 已提交
2622 2623 2624
> **NOTE**
> This API is deprecated since API Version 9. Use [getAssets](js-apis-photoAccessHelper.md#getassets) instead.

2625 2626 2627 2628 2629 2630 2631 2632
**Required permissions**: ohos.permission.READ_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

| Name  | Type                                               | Mandatory| Description                               |
| -------- | --------------------------------------------------- | ---- | ----------------------------------- |
A
Annie_wang 已提交
2633
| callback | AsyncCallback<[FetchFileResult](#fetchfileresult7)> | Yes  | Callback invoked to return the file retrieval result set of the album.|
2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656

**Example**

```js
async function example() {
  // To obtain the file assets in an album, you must preset the album and resources. The sample code below presets 'New Album 1'.
  let AlbumNoArgsfetchOp = {
    selections: mediaLibrary.FileKey.ALBUM_NAME + '= ?',
    selectionArgs:['New Album 1'],
  };
  // Obtain the albums that meet the retrieval options and return the album list.
  const albumList = await media.getAlbums(AlbumNoArgsfetchOp);
  const album = albumList[0];
  // Obtain an album from the album list and obtain all media assets that meet the retrieval options in the album.
  album.getFileAssets((error, fetchFileResult) => {
    if (error) {
      console.error('album getFileAssets failed with error: ' + error);
      return;
    }
    let count = fetchFileResult.getCount();
    console.info('album getFileAssets successfully, count: ' + count);
    fetchFileResult.close();
  });
W
wusongqing 已提交
2657 2658 2659
}
```

W
wusongqing 已提交
2660
### getFileAssets<sup>7+</sup>
W
wusongqing 已提交
2661 2662 2663

getFileAssets(options: MediaFetchOptions, callback: AsyncCallback&lt;FetchFileResult&gt;): void

A
Annie_wang 已提交
2664 2665 2666 2667
Obtains the file assets in this album based on specified conditions. This API uses an asynchronous callback to return the result.

> **NOTE**
> This API is deprecated since API Version 9. Use [getAssets](js-apis-photoAccessHelper.md#getassets) instead.
W
wusongqing 已提交
2668 2669 2670 2671 2672 2673 2674

**Required permissions**: ohos.permission.READ_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
2675 2676 2677
| Name  | Type                                               | Mandatory| Description                               |
| -------- | --------------------------------------------------- | ---- | ----------------------------------- |
| options  | [MediaFetchOptions](#mediafetchoptions7)            | Yes  | Options for fetching the files.                     |
A
Annie_wang 已提交
2678
| callback | AsyncCallback<[FetchFileResult](#fetchfileresult7)> | Yes  | Callback invoked to return the file retrieval result set of the album.|
W
wusongqing 已提交
2679 2680 2681

**Example**

2682
```js
W
wusongqing 已提交
2683
async function example() {
2684 2685 2686 2687 2688 2689 2690 2691
  // To obtain the file assets in an album, you must preset the album and resources. The sample code below presets 'New Album 1'.
  let AlbumNoArgsfetchOp = {
    selections: mediaLibrary.FileKey.ALBUM_NAME + '= ?',
    selectionArgs:['New Album 1'],
  };
  let fileNoArgsfetchOp = {
    selections: '',
    selectionArgs: [],
A
Annie_wang 已提交
2692
  };
2693 2694 2695 2696 2697 2698 2699 2700
  // Obtain the albums that meet the retrieval options and return the album list.
  const albumList = await media.getAlbums(AlbumNoArgsfetchOp);
  const album = albumList[0];
  // Obtain an album from the album list and obtain all media assets that meet the retrieval options in the album.
  album.getFileAssets(fileNoArgsfetchOp, (error, fetchFileResult) => {
    if (error) {
      console.error('album getFileAssets failed with error: ' + error);
      return;
W
wusongqing 已提交
2701
    }
2702 2703 2704 2705
    let count = fetchFileResult.getCount();
    console.info('album getFileAssets successfully, count: ' + count);
    fetchFileResult.close();
  });
W
wusongqing 已提交
2706 2707 2708
}
```

W
wusongqing 已提交
2709
### getFileAssets<sup>7+</sup>
W
wusongqing 已提交
2710 2711 2712

 getFileAssets(options?: MediaFetchOptions): Promise&lt;FetchFileResult&gt;

A
Annie_wang 已提交
2713 2714 2715 2716
Obtains the file assets in this album based on specified conditions. This API uses a promise to return the result.

> **NOTE**
> This API is deprecated since API Version 9. Use [getAssets](js-apis-photoAccessHelper.md#getassets-1) instead.
W
wusongqing 已提交
2717 2718 2719 2720 2721 2722 2723

**Required permissions**: ohos.permission.READ_MEDIA

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

**Parameters**

W
wusongqing 已提交
2724 2725 2726
| Name | Type                                    | Mandatory| Description          |
| ------- | ---------------------------------------- | ---- | -------------- |
| options | [MediaFetchOptions](#mediafetchoptions7) | No  | Options for fetching the files.|
W
wusongqing 已提交
2727 2728 2729

**Return value**

W
wusongqing 已提交
2730 2731
| Type                                         | Description                     |
| --------------------------------------------- | ------------------------- |
A
Annie_wang 已提交
2732
| Promise<[FetchFileResult](#fetchfileresult7)> | Promise used to return the file retrieval result set of the album.|
W
wusongqing 已提交
2733 2734 2735

**Example**

2736
```js
W
wusongqing 已提交
2737
async function example() {
2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757
  // To obtain the file assets in an album, you must preset the album and resources. The sample code below presets 'New Album 1'.
  let AlbumNoArgsfetchOp = {
    selections: mediaLibrary.FileKey.ALBUM_NAME + '= ?',
    selectionArgs:['New Album 1'],
  };
  let fileNoArgsfetchOp = {
    selections: '',
    selectionArgs: [],
  };
  // Obtain the albums that meet the retrieval options and return the album list.
  const albumList = await media.getAlbums(AlbumNoArgsfetchOp);
  const album = albumList[0];
  // Obtain an album from the album list and obtain all media assets that meet the retrieval options in the album.
  album.getFileAssets(fileNoArgsfetchOp).then((fetchFileResult) => {
    let count = fetchFileResult.getCount();
    console.info('album getFileAssets successfully, count: ' + count);
    fetchFileResult.close();
  }).catch((error) => {
    console.error('album getFileAssets failed with error: ' + error);
  });
W
wusongqing 已提交
2758 2759 2760 2761 2762
}
```

## PeerInfo<sup>8+</sup>

A
Annie_wang 已提交
2763
Defines information about a registered device.
2764

A
Annie_wang 已提交
2765 2766 2767
> **NOTE**
> This API is deprecated since API Version 9. There is no substitute API.

2768
**System API**: This is a system API.
W
wusongqing 已提交
2769

W
wusongqing 已提交
2770
**System capability**: SystemCapability.Multimedia.MediaLibrary.DistributedCore
W
wusongqing 已提交
2771

W
wusongqing 已提交
2772 2773 2774 2775 2776 2777
| Name      | Type                      | Readable| Writable| Description            |
| ---------- | -------------------------- | ---- | ---- | ---------------- |
| deviceName | string                     | Yes  | No  | Name of the registered device.  |
| networkId  | string                     | Yes  | No  | Network ID of the registered device.|
| deviceType | [DeviceType](#devicetype8) | Yes  | No  | Type of the registered device.        |
| isOnline   | boolean                    | Yes  | No  | Whether the registered device is online.        |
W
wusongqing 已提交
2778

W
wusongqing 已提交
2779
## MediaType<sup>8+</sup>
W
wusongqing 已提交
2780 2781 2782

Enumerates media types.

A
Annie_wang 已提交
2783 2784 2785
> **NOTE**
> This API is deprecated since API Version 9. Use [PhotoType](js-apis-photoAccessHelper.md#phototype) instead.

W
wusongqing 已提交
2786 2787
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

2788 2789 2790 2791 2792 2793
| Name |  Value|  Description|
| ----- |  ---- | ---- |
| FILE  |  0 | File.|
| IMAGE |  1 | Image.|
| VIDEO |  2 | Video.|
| AUDIO |  3 | Audio.|
W
wusongqing 已提交
2794

W
wusongqing 已提交
2795
## FileKey<sup>8+</sup>
W
wusongqing 已提交
2796 2797 2798

Enumerates key file information.

G
gloria 已提交
2799
> **NOTE**
A
Annie_wang 已提交
2800 2801 2802
>
> - The **bucket_id** field may change after file rename or movement. Therefore, you must obtain the field again before using it.
> - This API is deprecated since API Version 9. Use [PhotoKeys](js-apis-photoAccessHelper.md#photokeys) instead.
G
gloria 已提交
2803

W
wusongqing 已提交
2804 2805
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

2806
| Name         | Value             | Description                                                      |
W
wusongqing 已提交
2807
| ------------- | ------------------- | ---------------------------------------------------------- |
G
Gloria 已提交
2808
| ID            | 'file_id'             | File ID.                                                  |
A
Annie_wang 已提交
2809 2810
| RELATIVE_PATH | 'relative_path'       | Relative path of the user directory.                                          |
| DISPLAY_NAME  | 'display_name'        | File name displayed.                                                  |
G
Gloria 已提交
2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826
| PARENT        | 'parent'              | Parent directory ID.                                                  |
| MIME_TYPE     | 'mime_type'           | Extended file attributes, such as image/, video/, and file/*.                                            |
| MEDIA_TYPE    | 'media_type'          | Media type.                                                  |
| SIZE          | 'size'                | File size, in bytes.                                    |
| 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 content (not the file name) was last modified. The value is the number of seconds elapsed since the Epoch time.|
| DATE_TAKEN    | 'date_taken'          | Date when the file (photo) was taken. The value is the number of seconds elapsed since the Epoch time.            |
| TITLE         | 'title'               | Title in the file.                                                  |
| ARTIST        | 'artist'              | Artist of the file.                                                      |
| AUDIOALBUM    | 'audio_album'         | Audio album.                                                      |
| DURATION      | 'duration'            | Duration, in ms.                                      |
| WIDTH         | 'width'               | Image width, in pixels.                                    |
| HEIGHT        | 'height'              | Image height, in pixels.                                    |
| ORIENTATION   | 'orientation'         | Image display direction (clockwise rotation angle, for example, 0, 90, and 180, in degrees).|
| ALBUM_ID      | 'bucket_id'           | ID of the album to which the file belongs.                                      |
| ALBUM_NAME    | 'bucket_display_name' | Name of the album to which the file belongs.                                        |
W
wusongqing 已提交
2827

W
wusongqing 已提交
2828
## DirectoryType<sup>8+</sup>
W
wusongqing 已提交
2829 2830 2831

Enumerates directory types.

A
Annie_wang 已提交
2832 2833 2834
> **NOTE**
> This API is deprecated since API Version 9. There is no substitute API.

W
wusongqing 已提交
2835 2836
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

2837 2838 2839 2840 2841 2842 2843 2844
| Name         | Value|  Description              |
| ------------- | --- | ------------------ |
| DIR_CAMERA    |  0 | Directory of camera files.|
| DIR_VIDEO     |  1 |  Directory of video files.      |
| DIR_IMAGE     |  2 | Directory of image files.      |
| DIR_AUDIO     |  3 | Directory of audio files.      |
| DIR_DOCUMENTS |  4 | Directory of documents.      |
| DIR_DOWNLOAD  |  5 |  Download directory.      |
W
wusongqing 已提交
2845

W
wusongqing 已提交
2846
## DeviceType<sup>8+</sup>
W
wusongqing 已提交
2847

A
Annie_wang 已提交
2848
Enumerates the device types.
2849

A
Annie_wang 已提交
2850 2851 2852
> **NOTE**
> This API is deprecated since API Version 9. There is no substitute API.

2853
**System API**: This is a system API.
W
wusongqing 已提交
2854

W
wusongqing 已提交
2855
**System capability**: SystemCapability.Multimedia.MediaLibrary.DistributedCore
W
wusongqing 已提交
2856

2857 2858 2859 2860 2861 2862 2863 2864 2865
| Name        |  Value| Description      |
| ------------ | --- | ---------- |
| TYPE_UNKNOWN |  0 | Unknown.|
| TYPE_LAPTOP  |  1 | Laptop.|
| TYPE_PHONE   |  2 | Phone.      |
| TYPE_TABLET  |  3 | Tablet.  |
| TYPE_WATCH   |  4 | Smart watch.  |
| TYPE_CAR     |  5 | Vehicle-mounted device.  |
| TYPE_TV      |  6 | TV.  |
W
wusongqing 已提交
2866

W
wusongqing 已提交
2867
## MediaFetchOptions<sup>7+</sup>
W
wusongqing 已提交
2868

A
Annie_wang 已提交
2869
Defines the options for fetching media files.
W
wusongqing 已提交
2870

A
Annie_wang 已提交
2871 2872 2873
> **NOTE**
> This API is deprecated since API Version 9. Use [FetchOptions](js-apis-photoAccessHelper.md#fetchoptions) instead.

W
wusongqing 已提交
2874 2875
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

2876 2877
| Name                   | Type               | Readable| Writable| Description                                                        |
| ----------------------- | ------------------- | ---- | ---- | ------------------------------------------------------------ |
A
Annie_wang 已提交
2878 2879
| selections              | string              | Yes  | Yes  | Conditions for fetching files. The enumerated values in [FileKey](#filekey8) are used as the column names when files are fetched. Example:<br>selections: mediaLibrary.FileKey.MEDIA_TYPE + '= ? OR ' + mediaLibrary.FileKey.MEDIA_TYPE + '= ?', |
| selectionArgs           | Array&lt;string&gt; | Yes  | Yes  | Values of the conditions specified in **selections**.<br>Example:<br>selectionArgs: [mediaLibrary.MediaType.IMAGE.toString(), mediaLibrary.MediaType.VIDEO.toString()], |
G
Gloria 已提交
2880
| order                   | string              | Yes  | Yes  | Sorting mode of the search results, which can be ascending or descending. The enumerated values in [FileKey](#filekey8) are used as the columns for sorting the search results. Example:<br>Ascending: order: mediaLibrary.FileKey.DATE_ADDED + ' ASC'<br>Descending: order: mediaLibrary.FileKey.DATE_ADDED + ' DESC'|
A
Annie_wang 已提交
2881
| uri<sup>8+</sup>        | string              | Yes  | Yes  | URI of the file.                                                     |
2882 2883
| networkId<sup>8+</sup>  | string              | Yes  | Yes  | Network ID of the registered device.                                              |
| extendArgs<sup>8+</sup> | string              | Yes  | Yes  | Extended parameters for fetching the files. Currently, no extended parameters are available.                        |
W
wusongqing 已提交
2884 2885 2886

## Size<sup>8+</sup>

A
Annie_wang 已提交
2887
Defines the image size.
2888

A
Annie_wang 已提交
2889 2890 2891
> **NOTE**
> This API is deprecated since API Version 9. Use [image.Size](js-apis-image.md#size) instead.

W
wusongqing 已提交
2892
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core
W
wusongqing 已提交
2893

W
wusongqing 已提交
2894 2895 2896 2897
| Name    | Type    | Readable  | Writable  | Description      |
| ------ | ------ | ---- | ---- | -------- |
| width  | number | Yes   | Yes   | Image width, in pixels.|
| height | number | Yes   | Yes   | Image height, in pixels.|
W
wusongqing 已提交
2898

G
Gloria 已提交
2899
## MediaAssetOption
W
wusongqing 已提交
2900

A
Annie_wang 已提交
2901
Defines the media asset option.
W
wusongqing 已提交
2902

A
Annie_wang 已提交
2903 2904 2905
> **NOTE**
> This API is deprecated since API Version 9. There is no substitute API.

W
wusongqing 已提交
2906 2907
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

2908 2909 2910 2911
| Name        | Type  | Readable| Writable| Description                                                        |
| ------------ | ------ | ---- | ---- | ------------------------------------------------------------ |
| src          | string | Yes  | Yes  | Application sandbox oath of the local file.                                      |
| mimeType     | string | Yes  | Yes  | Multipurpose Internet Mail Extensions (MIME) type of the media.<br>The value can be 'image/\*', 'video/\*', 'audio/\*' or 'file\*'.|
A
Annie_wang 已提交
2912
| relativePath | string | Yes  | Yes  | Custom path of media assets, for example, **Pictures/**. If this parameter is unspecified, media assets are stored in the default path.<br> Default path of images: **'Pictures/'**<br> Default path of videos: **'Videos/'**<br> Default path of audios: **'Audios/'**<br> Default path of documents: **'Documents/'**|
W
wusongqing 已提交
2913

G
Gloria 已提交
2914
## MediaSelectOption
W
wusongqing 已提交
2915

A
Annie_wang 已提交
2916 2917 2918 2919
Defines the media selection option.

> **NOTE**
> This API is deprecated since API Version 9. There is no substitute API.
W
wusongqing 已提交
2920 2921 2922

**System capability**: SystemCapability.Multimedia.MediaLibrary.Core

2923 2924
| Name   | Type    | Readable| Writable| Description                  |
| ----- | ------ | ---- | ---- | -------------------- |
G
gloria 已提交
2925
| type  | 'image' &#124; 'video' &#124; 'media' | Yes   | Yes | Media type, which can be **image**, **media**, or **video**. Currently, only **media** is supported.|
G
Gloria 已提交
2926
| count | number | Yes   | Yes | Maximum number of media assets that can be selected. The value starts from 1, which indicates that one media asset can be selected.           |