• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.file.sendablePhotoAccessHelper (Album Management Based on a Sendable object)
2
3The sendablePhotoAccessHelper module provides APIs for album management, including creating an album and accessing and modifying media data in an album, based on a Sendable object.
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 12. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8
9## Modules to Import
10
11```ts
12import { sendablePhotoAccessHelper } from '@kit.MediaLibraryKit';
13```
14
15## sendablePhotoAccessHelper.getPhotoAccessHelper
16
17getPhotoAccessHelper(context: Context): PhotoAccessHelper
18
19Obtains a **PhotoAccessHelper** instance, which can be used for accessing and modifying media files in an album.
20
21**Model restriction**: This API can be used only in the stage model.
22
23**Atomic service API**: This API can be used in atomic services since API version 12.
24
25**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
26
27**Parameters**
28
29| Name | Type                                                        | Mandatory| Description                      |
30| ------- | ------------------------------------------------------------ | ---- | -------------------------- |
31| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes  | Context of the ability instance.|
32
33**Return value**
34
35| Type                                   | Description                |
36| --------------------------------------- | :------------------- |
37| [PhotoAccessHelper](#photoaccesshelper) | **PhotoAccessHelper** instance obtained.|
38
39**Error codes**
40
41For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
42
43| ID| Error Message                                                    |
44| -------- | ------------------------------------------------------------ |
45| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
46
47**Example**
48
49```ts
50// The phAccessHelper instance obtained is a global object. It is used by default in subsequent operations. If the code snippet is not added, an error will be reported indicating that phAccessHelper is not defined.
51let context = getContext(this);
52let phAccessHelper = sendablePhotoAccessHelper.getPhotoAccessHelper(context);
53```
54
55## PhotoAccessHelper
56
57### getAssets
58
59getAssets(options: FetchOptions): Promise<FetchResult<PhotoAsset>>
60
61Obtains media assets. This API uses a promise to return the result.
62
63**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
64
65**Required permissions**: ohos.permission.READ_IMAGEVIDEO
66
67If the caller does not have the ohos.permission.READ_IMAGEVIDEO permission, use Picker to access the file and then call this API based on the URI obtained by Picker. For details, see [Obtaining an Image or Video by URI](../../media/medialibrary/photoAccessHelper-photoviewpicker.md#obtaining-an-image-or-video-by-uri).
68
69**Parameters**
70
71| Name | Type                                                     | Mandatory| Description                |
72| ------- | --------------------------------------------------------- | ---- | -------------------- |
73| options | [FetchOptions](js-apis-photoAccessHelper.md#fetchoptions) | Yes  | Options for fetching the media assets.|
74
75**Return value**
76
77| Type                                                        | Description                                   |
78| ------------------------------------------------------------ | --------------------------------------- |
79| Promise<[FetchResult](#fetchresult)<[PhotoAsset](#photoasset)>> | Promise used to return the media assets obtained.|
80
81**Error codes**
82
83For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
84
85| ID| Error Message                                                    |
86| -------- | ------------------------------------------------------------ |
87| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
88| 201      | Permission denied.                                           |
89| 13900020 | Invalid argument.                                            |
90| 14000011 | Internal system error                                        |
91
92**Example**
93
94
95
96```ts
97import { dataSharePredicates } from '@kit.ArkData';
98import { photoAccessHelper } from '@kit.MediaLibraryKit';
99
100async function example() {
101  console.info('getAssets');
102  let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
103  let fetchOptions: photoAccessHelper.FetchOptions = {
104    fetchColumns: [],
105    predicates: predicates
106  };
107  try {
108    let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions);
109    if (fetchResult !== undefined) {
110      console.info('fetchResult success');
111      let photoAsset: sendablePhotoAccessHelper.PhotoAsset = await fetchResult.getFirstObject();
112      if (photoAsset !== undefined) {
113        console.info('photoAsset.displayName :' + photoAsset.displayName);
114      }
115    }
116  } catch (err) {
117    console.error(`getAssets failed, error: ${err.code}, ${err.message}`);
118  }
119}
120```
121
122### getBurstAssets
123
124getBurstAssets(burstKey: string, options: FetchOptions): Promise&lt;FetchResult&lt;PhotoAsset&gt;&gt;
125
126Obtains burst assets. This API uses a promise to return the result.
127
128**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
129
130**Required permissions**: ohos.permission.READ_IMAGEVIDEO
131
132**Parameters**
133
134| Name  | Type                                                     | Mandatory| Description                                                        |
135| -------- | --------------------------------------------------------- | ---- | ------------------------------------------------------------ |
136| burstKey | string                                                    | Yes  | Universally Unique Identifier (UUID) of a group of burst photos, that is, **BURST_KEY** of [PhotoKeys](js-apis-photoAccessHelper.md#photokeys).|
137| options  | [FetchOptions](js-apis-photoAccessHelper.md#fetchoptions) | Yes  | Options for fetching the burst photos.                                          |
138
139**Return value**
140
141| Type                                                        | Description                                 |
142| ------------------------------------------------------------ | ------------------------------------- |
143| Promise&lt;[FetchResult](#fetchresult)&lt;[PhotoAsset](#photoasset)&gt;&gt; | Promise used to return the result.|
144
145**Error codes**
146
147For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
148
149| ID| Error Message                                                    |
150| -------- | ------------------------------------------------------------ |
151| 201      | Permission denied.                                           |
152| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
153| 14000011 | Internal system error.                                       |
154
155**Example**
156
157```ts
158import { photoAccessHelper } from '@kit.MediaLibraryKit';
159import { dataSharePredicates } from '@kit.ArkData';
160
161async function example() {
162  console.info('getBurstAssets');
163  let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
164  let fetchOption: photoAccessHelper.FetchOptions = {
165    fetchColumns: [],
166    predicates: predicates
167  };
168  let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption);
169  let photoAssetList: Array<sendablePhotoAccessHelper.PhotoAsset> = await fetchResult.getAllObjects();
170  let photoAsset: sendablePhotoAccessHelper.PhotoAsset;
171  // burstKey is a 36-bit UUID, which can be obtained from photoAccessHelper.PhotoKeys.
172  for(photoAsset of photoAssetList){
173      let burstKey: string = photoAccessHelper.PhotoKeys.BURST_KEY.toString();
174      let photoAccessBurstKey: photoAccessHelper.MemberType = photoAsset.get(burstKey).toString();
175      try {
176         let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await
177      phAccessHelper.getBurstAssets(photoAccessBurstKey, fetchOption);
178         if (fetchResult !== undefined) {
179           console.info('fetchResult success');
180           let photoAsset: sendablePhotoAccessHelper.PhotoAsset = await fetchResult.getFirstObject();
181           if (photoAsset !== undefined) {
182              console.info('photoAsset.displayName :' + photoAsset.displayName);
183      }
184    }
185  } catch (err) {
186    console.error(`getBurstAssets failed, error: ${err.code}, ${err.message}`);
187  }
188}
189}
190```
191
192### createAsset
193
194createAsset(photoType: PhotoType, extension: string, options?: CreateOptions): Promise&lt;string&gt;
195
196Creates a media asset with the specified file type, file name extension, and options. This API uses a promise to return the result.
197
198If the caller does not have the ohos.permission.WRITE_IMAGEVIDEO permission, you can create a media asset by using a security component. For details, see [Creating a Media Asset Using a Security Component](../../media/medialibrary/photoAccessHelper-savebutton.md).
199
200**Atomic service API**: This API can be used in atomic services since API version 12.
201
202**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
203
204**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
205
206**Parameters**
207
208| Name   | Type                                                       | Mandatory| Description                                |
209| --------- | ----------------------------------------------------------- | ---- | ------------------------------------ |
210| photoType | [PhotoType](#phototype)                                     | Yes  | Type of the file to create, which can be **IMAGE** or **VIDEO**.|
211| extension | string                                                      | Yes  | File name extension, for example, **'jpg'**.       |
212| options   | [CreateOptions](js-apis-photoAccessHelper.md#createoptions) | No  | Options for creating the media asset, for example, **{title: 'testPhoto'}**.|
213
214**Return value**
215
216| Type                 | Description                                    |
217| --------------------- | ---------------------------------------- |
218| Promise&lt;string&gt; | Promise used to return the URI of the created media asset.|
219
220**Error codes**
221
222For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
223
224| ID| Error Message                                                    |
225| -------- | ------------------------------------------------------------ |
226| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
227| 201      | Permission denied.                                           |
228| 13900020 | Invalid argument.                                            |
229| 14000011 | Internal system error.                                        |
230
231**Example**
232
233```ts
234import { photoAccessHelper } from '@kit.MediaLibraryKit';
235
236async function example() {
237  console.info('createAssetDemo');
238  try {
239    let photoType: sendablePhotoAccessHelper.PhotoType = sendablePhotoAccessHelper.PhotoType.IMAGE;
240    let extension: string = 'jpg';
241    let options: photoAccessHelper.CreateOptions = {
242      title: 'testPhoto'
243    }
244    let uri: string = await phAccessHelper.createAsset(photoType, extension, options);
245    console.info('createAsset uri' + uri);
246    console.info('createAsset successfully');
247  } catch (err) {
248    console.error(`createAsset failed, error: ${err.code}, ${err.message}`);
249  }
250}
251```
252
253### getAlbums
254
255getAlbums(type: AlbumType, subtype: AlbumSubtype, options?: FetchOptions): Promise&lt;FetchResult&lt;Album&gt;&gt;
256
257Obtains albums based on the specified options and album type. This API uses a promise to return the result.
258
259Before the operation, ensure that the albums to obtain exist.
260
261**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
262
263**Required permissions**: ohos.permission.READ_IMAGEVIDEO
264
265**Parameters**
266
267| Name | Type                                                     | Mandatory| Description                                  |
268| ------- | --------------------------------------------------------- | ---- | -------------------------------------- |
269| type    | [AlbumType](#albumtype)                                   | Yes  | Type of the albums to obtain.                            |
270| subtype | [AlbumSubtype](#albumsubtype)                             | Yes  | Subtype of the album.                          |
271| options | [FetchOptions](js-apis-photoAccessHelper.md#fetchoptions) | No  | Options for fetching the albums. If this parameter is not specified, the albums are obtained based on the album type by default.|
272
273**Return value**
274
275| Type                                                        | Description                               |
276| ------------------------------------------------------------ | ----------------------------------- |
277| Promise&lt;[FetchResult](#fetchresult)&lt;[Album](#album)&gt;&gt; | Promise used to return the result.|
278
279**Error codes**
280
281For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
282
283| ID| Error Message                                                    |
284| -------- | ------------------------------------------------------------ |
285| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
286| 201      | Permission denied.                                           |
287| 13900020 | Invalid argument.                                            |
288| 14000011 | Internal system error                                        |
289
290**Example**
291
292```ts
293import { dataSharePredicates } from '@kit.ArkData';
294import { BusinessError } from '@kit.BasicServicesKit';
295import { photoAccessHelper } from '@kit.MediaLibraryKit';
296
297async function example() {
298  // Obtain the album named newAlbumName.
299  console.info('getAlbumsDemo');
300  let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
301  predicates.equalTo('album_name', 'newAlbumName');
302  let fetchOptions: photoAccessHelper.FetchOptions = {
303    fetchColumns: [],
304    predicates: predicates
305  };
306  phAccessHelper.getAlbums(sendablePhotoAccessHelper.AlbumType.USER, sendablePhotoAccessHelper.AlbumSubtype.USER_GENERIC, fetchOptions).then( async (fetchResult) => {
307    if (fetchResult === undefined) {
308      console.error('getAlbumsPromise fetchResult is undefined');
309      return;
310    }
311    let album: sendablePhotoAccessHelper.Album = await fetchResult.getFirstObject();
312    console.info('getAlbumsPromise successfully, albumName: ' + album.albumName);
313    fetchResult.close();
314  }).catch((err: BusinessError) => {
315    console.error(`getAlbumsPromise failed with err: ${err.code}, ${err.message}`);
316  });
317}
318```
319
320### getAlbums
321
322getAlbums(options: FetchOptions): Promise&lt;FetchResult&lt;Album&gt;&gt;
323
324Obtains albums. This API uses a promise to return the result.
325
326Before the operation, ensure that the albums to obtain exist.
327
328**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
329
330**Required permissions**: ohos.permission.READ_IMAGEVIDEO
331
332**Parameters**
333
334| Name | Type                                                     | Mandatory| Description    |
335| ------- | --------------------------------------------------------- | ---- | -------- |
336| options | [FetchOptions](js-apis-photoAccessHelper.md#fetchoptions) | Yes  | Options for obtaining the albums.|
337
338**Return value**
339
340| Type                                                        | Description                               |
341| ------------------------------------------------------------ | ----------------------------------- |
342| Promise&lt;[FetchResult](#fetchresult)&lt;[Album](#album)&gt;&gt; | Promise used to return the result.|
343
344**Error codes**
345
346For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
347
348| ID| Error Message                                                    |
349| -------- | ------------------------------------------------------------ |
350| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
351| 201      | Permission denied.                                           |
352| 13900020 | Invalid argument.                                            |
353| 14000011 | Internal system error                                        |
354
355**Example**
356
357```ts
358import { dataSharePredicates } from '@kit.ArkData';
359import { BusinessError } from '@kit.BasicServicesKit';
360import { photoAccessHelper } from '@kit.MediaLibraryKit';
361
362async function example() {
363  // Obtain the album named newAlbumName.
364  console.info('getAlbumsDemo');
365  let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
366  predicates.equalTo('album_name', 'newAlbumName');
367  let fetchOptions: photoAccessHelper.FetchOptions = {
368    fetchColumns: [],
369    predicates: predicates
370  };
371  phAccessHelper.getAlbums(fetchOptions).then( async (fetchResult) => {
372    if (fetchResult === undefined) {
373      console.error('getAlbumsPromise fetchResult is undefined');
374      return;
375    }
376    let album: sendablePhotoAccessHelper.Album = await fetchResult.getFirstObject();
377    console.info('getAlbumsPromise successfully, albumName: ' + album.albumName);
378    fetchResult.close();
379  }).catch((err: BusinessError) => {
380    console.error(`getAlbumsPromise failed with err: ${err.code}, ${err.message}`);
381  });
382}
383```
384
385### release
386
387release(): Promise&lt;void&gt;
388
389Releases this **PhotoAccessHelper** instance. This API uses a promise to return the result.
390Call this API when the APIs of the **PhotoAccessHelper** instance are no longer used.
391
392**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
393
394**Return value**
395
396| Type               | Description                   |
397| ------------------- | ----------------------- |
398| Promise&lt;void&gt; | Promise that returns no value.|
399
400**Error codes**
401
402For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
403
404| ID| Error Message                                                    |
405| -------- | ------------------------------------------------------------ |
406| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
407| 13900020 | Invalid argument.                                            |
408| 14000011 | Internal system error                                        |
409
410**Example**
411
412```ts
413async function example() {
414  console.info('releaseDemo');
415  try {
416    console.info('use function...');
417  } catch (err) {
418    console.error(`function error ...`);
419  }finally{
420      try{
421          phAccessHelper?.release();
422          console.info(`release success`);
423      } catch(e){
424          console.error(`release error :${e}`);
425      }
426  }
427}
428```
429
430## PhotoAsset
431
432Provides APIs for encapsulating file asset attributes.
433
434### Properties
435
436**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
437
438| Name       | Type                   | Read-Only| Optional| Description                                                        |
439| ----------- | ----------------------- | ---- | ---- | ------------------------------------------------------------ |
440| uri         | string                  | Yes  | No  | Media asset URI, for example, **file://media/Photo/1/IMG_datetime_0001/displayName.jpg**. For details, see [Media File URI](../../file-management/user-file-uri-intro.md#media-file-uri).|
441| photoType   | [PhotoType](#phototype) | Yes  | No  | Type of the file.                                              |
442| displayName | string                  | Yes  | No  | File name, including the file name extension, to display.                                    |
443
444### convertToPhotoAsset
445
446convertToPhotoAsset():  photoAccessHelper.PhotoAsset
447
448Converts a Sendable **PhotoAsset** object to a non-Sendable **PhotoAsset** object.
449
450**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
451
452**Return value**
453
454| Type                        | Description                                                        |
455| ---------------------------- | ------------------------------------------------------------ |
456| photoAccessHelper.PhotoAsset | [PhotoAsset](js-apis-photoAccessHelper.md#photoasset) object of the non-Sendable type.|
457
458**Error codes**
459
460For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
461
462| ID| Error Message                                                    |
463| -------- | ------------------------------------------------------------ |
464| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
465| 13900020 | Invalid argument.                                            |
466| 14000014 | Member is not a valid PhotoKey.                              |
467
468**Example**
469
470```ts
471import { dataSharePredicates } from '@kit.ArkData';
472import { photoAccessHelper } from '@kit.MediaLibraryKit';
473
474async function example() {
475  console.info('convertToPhotoAssetDemo');
476  try {
477    let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
478    let fetchOption: photoAccessHelper.FetchOptions = {
479      fetchColumns: ['title'],
480      predicates: predicates
481    };
482    let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption);
483    let sendablePhotoAsset: sendablePhotoAccessHelper.PhotoAsset = await fetchResult.getFirstObject();
484    let photoAsset: photoAccessHelper.PhotoAsset = sendablePhotoAsset.convertToPhotoAsset();
485    console.log(`get no sendable uri success : ${photoAsset.uri}`);
486  } catch (err) {
487    console.error(`convertToPhotoAsset failed. error: ${err.code}, ${err.message}`);
488  }
489}
490```
491
492### get
493
494get(member: string): MemberType
495
496Obtains a **PhotoAsset** member parameter.
497
498**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
499
500**Parameters**
501
502| Name| Type  | Mandatory| Description                                                        |
503| ------ | ------ | ---- | ------------------------------------------------------------ |
504| member | string | Yes  | Name of the member parameter to obtain. <br>Except **'uri'**, **'media_type'**, **'subtype'**, and **'display_name'**, you must pass in [PhotoKeys](js-apis-photoAccessHelper.md#photokeys) in **fetchColumns**. For example, to obtain the title, pass in **fetchColumns: ['title']**.|
505
506**Return value**
507
508| Type                                                 | Description                        |
509| ----------------------------------------------------- | ---------------------------- |
510| [MemberType](js-apis-photoAccessHelper.md#membertype) | **PhotoAsset** member parameter obtained.|
511
512**Error codes**
513
514For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
515
516| ID| Error Message                                                    |
517| -------- | ------------------------------------------------------------ |
518| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
519| 13900020 | Invalid argument.                                            |
520| 14000014 | Member is not a valid PhotoKey.                              |
521
522**Example**
523
524```ts
525import { dataSharePredicates } from '@kit.ArkData';
526import { photoAccessHelper } from '@kit.MediaLibraryKit';
527
528async function example() {
529  console.info('photoAssetGetDemo');
530  try {
531    let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
532    let fetchOption: photoAccessHelper.FetchOptions = {
533      fetchColumns: ['title'],
534      predicates: predicates
535    };
536    let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption);
537    let photoAsset: sendablePhotoAccessHelper.PhotoAsset = await fetchResult.getFirstObject();
538    let title: photoAccessHelper.PhotoKeys = photoAccessHelper.PhotoKeys.TITLE;
539    let photoAssetTitle: photoAccessHelper.MemberType = photoAsset.get(title.toString());
540    console.info('photoAsset Get photoAssetTitle = ', photoAssetTitle);
541  } catch (err) {
542    console.error(`get failed. error: ${err.code}, ${err.message}`);
543  }
544}
545```
546
547### set
548
549set(member: string, value: string): void
550
551Sets a **PhotoAsset** member parameter.
552
553**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
554
555**Parameters**
556
557| Name| Type  | Mandatory| Description                                                        |
558| ------ | ------ | ---- | ------------------------------------------------------------ |
559| member | string | Yes  | Name of the parameter to set, for example, [PhotoKeys](js-apis-photoAccessHelper.md#photokeys).TITLE.|
560| value  | string | Yes  | Value to set. Only the value of [PhotoKeys](js-apis-photoAccessHelper.md#photokeys).TITLE can be changed.|
561
562**Error codes**
563
564For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
565
566| ID| Error Message                                                    |
567| -------- | ------------------------------------------------------------ |
568| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
569| 13900020 | Invalid argument.                                            |
570| 14000014 | Member is not a valid PhotoKey.                              |
571
572**Example**
573
574```ts
575import { dataSharePredicates } from '@kit.ArkData';
576import { photoAccessHelper } from '@kit.MediaLibraryKit';
577
578async function example() {
579  console.info('photoAssetSetDemo');
580  try {
581    let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
582    let fetchOption: photoAccessHelper.FetchOptions = {
583      fetchColumns: ['title'],
584      predicates: predicates
585    };
586    let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption);
587    let photoAsset: sendablePhotoAccessHelper.PhotoAsset = await fetchResult.getFirstObject();
588    let title: string = photoAccessHelper.PhotoKeys.TITLE.toString();
589    photoAsset.set(title, 'newTitle');
590  } catch (err) {
591    console.error(`set failed. error: ${err.code}, ${err.message}`);
592  }
593}
594```
595
596### commitModify
597
598commitModify(): Promise&lt;void&gt;
599
600Commits the modification on the file metadata to the database. This API uses a promise to return the result.
601
602**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
603
604**Atomic service API**: This API can be used in atomic services since API version 12.
605
606**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
607
608**Return value**
609
610| Type               | Description                   |
611| ------------------- | ----------------------- |
612| Promise&lt;void&gt; | Promise that returns no value.|
613
614**Error codes**
615
616For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
617
618| ID| Error Message                                                    |
619| -------- | ------------------------------------------------------------ |
620| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
621| 201      | Permission denied.                                           |
622| 13900020 | Invalid argument.                                            |
623| 14000001 | Invalid display name.                                        |
624| 14000011 | Internal system error                                        |
625
626**Example**
627
628```ts
629import { dataSharePredicates } from '@kit.ArkData';
630import { photoAccessHelper } from '@kit.MediaLibraryKit';
631
632async function example() {
633  console.info('commitModifyDemo');
634  let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
635  let fetchOption: photoAccessHelper.FetchOptions = {
636    fetchColumns: ['title'],
637    predicates: predicates
638  };
639  let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption);
640  let photoAsset: sendablePhotoAccessHelper.PhotoAsset = await fetchResult.getFirstObject();
641  let title: string = photoAccessHelper.PhotoKeys.TITLE.toString();
642  let photoAssetTitle: photoAccessHelper.MemberType = photoAsset.get(title);
643  console.info('photoAsset get photoAssetTitle = ', photoAssetTitle);
644  photoAsset.set(title, 'newTitle3');
645  try {
646    await photoAsset.commitModify();
647    let newPhotoAssetTitle: photoAccessHelper.MemberType = photoAsset.get(title);
648    console.info('photoAsset get newPhotoAssetTitle = ', newPhotoAssetTitle);
649  } catch (err) {
650    console.error(`commitModify failed. error: ${err.code}, ${err.message}`);
651  }
652}
653```
654
655### getThumbnail
656
657getThumbnail(size?: image.Size): Promise&lt;image.PixelMap&gt;
658
659Obtains the file thumbnail of the given size. This API uses a promise to return the result.
660
661**Required permissions**: ohos.permission.READ_IMAGEVIDEO
662
663**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
664
665**Parameters**
666
667| Name| Type                                                 | Mandatory| Description        |
668| ------ | ----------------------------------------------------- | ---- | ------------ |
669| size   | [image.Size](../apis-image-kit/js-apis-image.md#size) | No  | Size of the thumbnail.|
670
671**Return value**
672
673| Type                                                        | Description                               |
674| ------------------------------------------------------------ | ----------------------------------- |
675| Promise&lt;[image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)&gt; | Promise used to return the PixelMap of the thumbnail.|
676
677**Error codes**
678
679For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
680
681| ID| Error Message                                                    |
682| -------- | ------------------------------------------------------------ |
683| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
684| 201      | Permission denied.                                           |
685| 13900020 | Invalid argument.                                            |
686| 14000011 | Internal system error                                        |
687
688**Example**
689
690```ts
691import { dataSharePredicates } from '@kit.ArkData';
692import { image } from '@kit.ImageKit';
693import { BusinessError } from '@kit.BasicServicesKit';
694import { photoAccessHelper } from '@kit.MediaLibraryKit';
695
696async function example() {
697  console.info('getThumbnailDemo');
698  let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
699  let fetchOption: photoAccessHelper.FetchOptions = {
700    fetchColumns: [],
701    predicates: predicates
702  };
703  let size: image.Size = { width: 720, height: 720 };
704  let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption);
705  let asset = await fetchResult.getFirstObject();
706  console.info('asset displayName = ', asset.displayName);
707  asset.getThumbnail(size).then((pixelMap) => {
708    console.info('getThumbnail successful ' + pixelMap);
709  }).catch((err: BusinessError) => {
710    console.error(`getThumbnail fail with error: ${err.code}, ${err.message}`);
711  });
712}
713```
714
715## FetchResult
716
717Provides APIs to manage the file retrieval result.
718
719### getCount
720
721getCount(): number
722
723Obtains the total number of files in the result set.
724
725**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
726
727**Return value**
728
729| Type  | Description              |
730| ------ | ------------------ |
731| number | Total number of files obtained.|
732
733**Error codes**
734
735For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
736
737| ID| Error Message                                                    |
738| -------- | ------------------------------------------------------------ |
739| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
740| 13900020 | Invalid argument.                                            |
741| 14000011 | Internal system error                                        |
742
743**Example**
744
745```ts
746import { dataSharePredicates } from '@kit.ArkData';
747import { photoAccessHelper } from '@kit.MediaLibraryKit';
748
749async function example() {
750  console.info('getCountDemo');
751  let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
752  let fetchOption: photoAccessHelper.FetchOptions = {
753    fetchColumns: [],
754    predicates: predicates
755  };
756  let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption);
757  let fetchCount = fetchResult.getCount();
758  console.info('fetchCount = ', fetchCount);
759}
760```
761
762### isAfterLast
763
764isAfterLast(): boolean
765
766Checks whether the cursor is in the last row of the result set.
767
768**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
769
770**Return value**
771
772| Type   | Description                                                       |
773| ------- | ----------------------------------------------------------- |
774| boolean | Returns **true** if the cursor is in the last row of the result set; returns **false** otherwise.|
775
776**Error codes**
777
778For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
779
780| ID| Error Message                                                    |
781| -------- | ------------------------------------------------------------ |
782| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
783| 13900020 | Invalid argument.                                            |
784| 14000011 | Internal system error                                        |
785
786**Example**
787
788```ts
789import { dataSharePredicates } from '@kit.ArkData';
790import { photoAccessHelper } from '@kit.MediaLibraryKit';
791
792async function example() {
793  let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
794  let fetchOption: photoAccessHelper.FetchOptions = {
795    fetchColumns: [],
796    predicates: predicates
797  };
798  let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption);
799  let fetchCount = fetchResult.getCount();
800  console.info('count:' + fetchCount);
801  let photoAsset: sendablePhotoAccessHelper.PhotoAsset = await fetchResult.getLastObject();
802  if (fetchResult.isAfterLast()) {
803    console.info('photoAsset isAfterLast displayName = ', photoAsset.displayName);
804  } else {
805    console.info('photoAsset not isAfterLast.');
806  }
807}
808```
809
810### close
811
812close(): void
813
814Closes this **FetchFileResult** instance to invalidate it. After this instance is closed, the APIs in this instance cannot be invoked.
815
816**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
817
818**Error codes**
819
820For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
821
822| ID| Error Message                                                    |
823| -------- | ------------------------------------------------------------ |
824| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
825| 13900020 | Invalid argument.                                            |
826| 14000011 | Internal system error                                        |
827
828**Example**
829
830```ts
831import { dataSharePredicates } from '@kit.ArkData';
832import { photoAccessHelper } from '@kit.MediaLibraryKit';
833
834async function example() {
835  console.info('fetchResultCloseDemo');
836  let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
837  let fetchOption: photoAccessHelper.FetchOptions = {
838    fetchColumns: [],
839    predicates: predicates
840  };
841  try {
842    let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption);
843    fetchResult.close();
844    console.info('close succeed.');
845  } catch (err) {
846    console.error(`close fail. error: ${err.code}, ${err.message}`);
847  }
848}
849```
850
851### getFirstObject
852
853getFirstObject(): Promise&lt;T&gt;
854
855Obtains the first asset in the result set. This API uses a promise to return the result.
856
857**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
858
859**Return value**
860
861| Type            | Description                                 |
862| ---------------- | ------------------------------------- |
863| Promise&lt;T&gt; | Promise used to return the first object in the result set.|
864
865**Error codes**
866
867For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
868
869| ID| Error Message                                                    |
870| -------- | ------------------------------------------------------------ |
871| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
872| 13900020 | Invalid argument.                                            |
873| 14000011 | Internal system error                                        |
874
875**Example**
876
877```ts
878import { dataSharePredicates } from '@kit.ArkData';
879import { photoAccessHelper } from '@kit.MediaLibraryKit';
880
881async function example() {
882  console.info('getFirstObjectDemo');
883  let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
884  let fetchOption: photoAccessHelper.FetchOptions = {
885    fetchColumns: [],
886    predicates: predicates
887  };
888  let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption);
889  let photoAsset: sendablePhotoAccessHelper.PhotoAsset = await fetchResult.getFirstObject();
890  console.info('photoAsset displayName: ', photoAsset.displayName);
891}
892```
893
894### getNextObject
895
896getNextObject(): Promise&lt;T&gt;
897
898Obtains the next asset in the result set. This API uses a promise to return the result.
899Before using this API, you must use [isAfterLast()](#isafterlast) to check whether the current position is the end of the result set.
900
901**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
902
903**Return value**
904
905| Type            | Description                                 |
906| ---------------- | ------------------------------------- |
907| Promise&lt;T&gt; | Promise used to return the next object in the result set.|
908
909**Error codes**
910
911For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
912
913| ID| Error Message                                                    |
914| -------- | ------------------------------------------------------------ |
915| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
916| 13900020 | Invalid argument.                                            |
917| 14000011 | Internal system error                                        |
918
919**Example**
920
921```ts
922import { dataSharePredicates } from '@kit.ArkData';
923import { photoAccessHelper } from '@kit.MediaLibraryKit';
924
925async function example() {
926  console.info('getNextObjectDemo');
927  let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
928  let fetchOption: photoAccessHelper.FetchOptions = {
929    fetchColumns: [],
930    predicates: predicates
931  };
932  let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption);
933  await fetchResult.getFirstObject();
934    let photoAsset: sendablePhotoAccessHelper.PhotoAsset = await fetchResult.getNextObject();
935    console.info('photoAsset displayName: ', photoAsset.displayName);
936}
937```
938
939### getLastObject
940
941getLastObject(): Promise&lt;T&gt;
942
943Obtains the last asset in the result set. This API uses a promise to return the result.
944
945**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
946
947**Return value**
948
949| Type            | Description                                   |
950| ---------------- | --------------------------------------- |
951| Promise&lt;T&gt; | Promise used to return the last object in the result set.|
952
953**Error codes**
954
955For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
956
957| ID| Error Message                                                    |
958| -------- | ------------------------------------------------------------ |
959| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
960| 13900020 | Invalid argument.                                            |
961| 14000011 | Internal system error                                        |
962
963**Example**
964
965```ts
966import { dataSharePredicates } from '@kit.ArkData';
967import { photoAccessHelper } from '@kit.MediaLibraryKit';
968
969async function example() {
970  console.info('getLastObjectDemo');
971  let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
972  let fetchOption: photoAccessHelper.FetchOptions = {
973    fetchColumns: [],
974    predicates: predicates
975  };
976  let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption);
977  let photoAsset: sendablePhotoAccessHelper.PhotoAsset = await fetchResult.getLastObject();
978  console.info('photoAsset displayName: ', photoAsset.displayName);
979}
980```
981
982### getObjectByPosition
983
984getObjectByPosition(index: number): Promise&lt;T&gt;
985
986Obtains the asset with the given index in the result set. This API uses a promise to return the result.
987
988**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
989
990**Parameters**
991
992| Name| Type  | Mandatory| Description                         |
993| ------ | ------ | ---- | ----------------------------- |
994| index  | number | Yes  | Index of the asset to obtain. The value starts from **0**.|
995
996**Return value**
997
998| Type            | Description                                         |
999| ---------------- | --------------------------------------------- |
1000| Promise&lt;T&gt; | Promise used to return the asset obtained.|
1001
1002**Error codes**
1003
1004For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
1005
1006| ID| Error Message                                                    |
1007| -------- | ------------------------------------------------------------ |
1008| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1009| 13900020 | Invalid argument.                                            |
1010| 14000011 | Internal system error                                        |
1011
1012**Example**
1013
1014```ts
1015import { dataSharePredicates } from '@kit.ArkData';
1016import { photoAccessHelper } from '@kit.MediaLibraryKit';
1017
1018async function example() {
1019  console.info('getObjectByPositionDemo');
1020  let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
1021  let fetchOption: photoAccessHelper.FetchOptions = {
1022    fetchColumns: [],
1023    predicates: predicates
1024  };
1025  let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption);
1026  let photoAsset: sendablePhotoAccessHelper.PhotoAsset = await fetchResult.getObjectByPosition(0);
1027  console.info('photoAsset displayName: ', photoAsset.displayName);
1028}
1029```
1030
1031### getAllObjects
1032
1033getAllObjects(): Promise&lt;Array&lt;T&gt;&gt;
1034
1035Obtains all the file assets in the result set. This API uses a promise to return the result.
1036
1037**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
1038
1039**Return value**
1040
1041| Type                         | Description                                       |
1042| ----------------------------- | ------------------------------------------- |
1043| Promise&lt;Array&lt;T&gt;&gt; | Promise used to return all the assets in the result set.|
1044
1045**Error codes**
1046
1047For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
1048
1049| ID| Error Message                                                    |
1050| -------- | ------------------------------------------------------------ |
1051| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
1052| 13900020 | Invalid argument.                                            |
1053| 14000011 | Internal system error                                        |
1054
1055**Example**
1056
1057```ts
1058import { dataSharePredicates } from '@kit.ArkData';
1059import { photoAccessHelper } from '@kit.MediaLibraryKit';
1060
1061async function example() {
1062  console.info('getAllObjectDemo');
1063  let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
1064  let fetchOption: photoAccessHelper.FetchOptions = {
1065    fetchColumns: [],
1066    predicates: predicates
1067  };
1068  let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption);
1069  let photoAssetList: Array<sendablePhotoAccessHelper.PhotoAsset> = await fetchResult.getAllObjects();
1070  console.info('photoAssetList length: ', photoAssetList.length);
1071}
1072```
1073
1074## Album
1075
1076Provides APIs to manage albums.
1077
1078### Properties
1079
1080**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
1081
1082| Name        | Type                         | Read-Only                        | Optional| Description            |
1083| ------------ | ----------------------------- | ---------------------------- | ---- | ---------------- |
1084| albumType    | [AlbumType](#albumtype)       | Yes                          | No  | Type of the album.      |
1085| albumSubtype | [AlbumSubtype](#albumsubtype) | Yes                          | No  | Subtype of the album.    |
1086| albumName    | string                        | Yes for a user album; no for a system album.| No  | Name of the album.      |
1087| albumUri     | string                        | Yes                          | No  | URI of the album.       |
1088| count        | number                        | Yes                          | No  | Number of files in the album.|
1089| coverUri     | string                        | Yes                          | No  | URI of the cover file of the album.   |
1090| imageCount   | number                        | Yes                          | Yes  | Number of images in the album.|
1091| videoCount   | number                        | Yes                          | Yes  | Number of videos in the album.|
1092
1093### convertToPhotoAlbum
1094
1095convertToPhotoAlbum(): photoAccessHelper.Album
1096
1097Converts this Sendable album to a non-Sendable album.
1098
1099**Required permissions**: ohos.permission.READ_IMAGEVIDEO
1100
1101**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
1102
1103**Return value**
1104
1105| Type                   | Description                                                     |
1106| ----------------------- | --------------------------------------------------------- |
1107| photoAccessHelper.Album | Non-Sendable [Album](js-apis-photoAccessHelper.md#album).|
1108
1109**Error codes**
1110
1111For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
1112
1113| ID| Error Message                                                    |
1114| -------- | ------------------------------------------------------------ |
1115| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1116| 201      | Permission denied.                                           |
1117| 13900020 | Invalid argument.                                            |
1118| 14000011 | Internal system error                                        |
1119
1120**Example**
1121
1122```ts
1123import { dataSharePredicates } from '@kit.ArkData';
1124import { BusinessError } from '@kit.BasicServicesKit';
1125import { photoAccessHelper } from '@kit.MediaLibraryKit';
1126
1127async function example() {
1128  console.info('convertToPhotoAlbumDemo');
1129  let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
1130  let albumFetchOptions: photoAccessHelper.FetchOptions = {
1131    fetchColumns: [],
1132    predicates: predicates
1133  };
1134  let fetchOption: photoAccessHelper.FetchOptions = {
1135    fetchColumns: [],
1136    predicates: predicates
1137  };
1138  let albumList: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.Album> = await phAccessHelper.getAlbums(sendablePhotoAccessHelper.AlbumType.USER, sendablePhotoAccessHelper.AlbumSubtype.USER_GENERIC, albumFetchOptions);
1139  let sendableAlbum: sendablePhotoAccessHelper.Album = await albumList.getFirstObject();
1140  let album: photoAccessHelper.Album = sendableAlbum.convertToPhotoAlbum();
1141  album.getAssets(fetchOption).then((albumFetchResult) => {
1142    console.info('convertToPhotoAlbum successfully, getCount: ' + albumFetchResult.getCount());
1143  }).catch((err: BusinessError) => {
1144    console.error(`convertToPhotoAlbum failed with error: ${err.code}, ${err.message}`);
1145  });
1146}
1147```
1148
1149### getAssets
1150
1151getAssets(options: FetchOptions): Promise&lt;FetchResult&lt;PhotoAsset&gt;&gt;
1152
1153Obtains media assets. This API uses a promise to return the result.
1154
1155**Required permissions**: ohos.permission.READ_IMAGEVIDEO
1156
1157**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
1158
1159**Parameters**
1160
1161| Name | Type                                                     | Mandatory| Description      |
1162| ------- | --------------------------------------------------------- | ---- | ---------- |
1163| options | [FetchOptions](js-apis-photoAccessHelper.md#fetchoptions) | Yes  | Options for fetching the assets.|
1164
1165**Return value**
1166
1167| Type                                                        | Description                                   |
1168| ------------------------------------------------------------ | --------------------------------------- |
1169| Promise&lt;[FetchResult](#fetchresult)&lt;[PhotoAsset](#photoasset)&gt;&gt; | Promise used to return the media assets obtained.|
1170
1171**Error codes**
1172
1173For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
1174
1175| ID| Error Message                                                    |
1176| -------- | ------------------------------------------------------------ |
1177| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1178| 201      | Permission denied.                                           |
1179| 13900020 | Invalid argument.                                            |
1180| 14000011 | Internal system error                                        |
1181
1182**Example**
1183
1184```ts
1185import { dataSharePredicates } from '@kit.ArkData';
1186import { BusinessError } from '@kit.BasicServicesKit';
1187import { photoAccessHelper } from '@kit.MediaLibraryKit';
1188
1189async function example() {
1190  console.info('albumGetAssetsDemoPromise');
1191  let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
1192  let albumFetchOptions: photoAccessHelper.FetchOptions = {
1193    fetchColumns: [],
1194    predicates: predicates
1195  };
1196  let fetchOption: photoAccessHelper.FetchOptions = {
1197    fetchColumns: [],
1198    predicates: predicates
1199  };
1200  let albumList: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.Album> = await phAccessHelper.getAlbums(sendablePhotoAccessHelper.AlbumType.USER, sendablePhotoAccessHelper.AlbumSubtype.USER_GENERIC, albumFetchOptions);
1201  let album: sendablePhotoAccessHelper.Album = await albumList.getFirstObject();
1202  album.getAssets(fetchOption).then((albumFetchResult) => {
1203    console.info('album getAssets successfully, getCount: ' + albumFetchResult.getCount());
1204  }).catch((err: BusinessError) => {
1205    console.error(`album getAssets failed with error: ${err.code}, ${err.message}`);
1206  });
1207}
1208```
1209
1210### commitModify
1211
1212commitModify(): Promise&lt;void&gt;
1213
1214Commits the modification on the album attributes to the database. This API uses a promise to return the result.
1215
1216**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
1217
1218**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
1219
1220**Return value**
1221
1222| Type               | Description                   |
1223| ------------------- | ----------------------- |
1224| Promise&lt;void&gt; | Promise that returns no value.|
1225
1226**Error codes**
1227
1228For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
1229
1230| ID| Error Message                                                    |
1231| -------- | ------------------------------------------------------------ |
1232| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
1233| 201      | Permission denied.                                           |
1234| 13900020 | Invalid argument.                                            |
1235| 14000011 | Internal system error                                        |
1236
1237**Example**
1238
1239```ts
1240import { dataSharePredicates } from '@kit.ArkData';
1241import { BusinessError } from '@kit.BasicServicesKit';
1242import { photoAccessHelper } from '@kit.MediaLibraryKit';
1243
1244async function example() {
1245  console.info('albumCommitModifyDemo');
1246  let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
1247  let albumFetchOptions: photoAccessHelper.FetchOptions = {
1248    fetchColumns: [],
1249    predicates: predicates
1250  };
1251  let albumList: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.Album> = await phAccessHelper.getAlbums(sendablePhotoAccessHelper.AlbumType.USER, sendablePhotoAccessHelper.AlbumSubtype.USER_GENERIC, albumFetchOptions);
1252  let album: sendablePhotoAccessHelper.Album = await albumList.getFirstObject();
1253  album.albumName = 'hello';
1254  album.commitModify().then(() => {
1255    console.info('commitModify successfully');
1256  }).catch((err: BusinessError) => {
1257    console.error(`commitModify failed with error: ${err.code}, ${err.message}`);
1258  });
1259}
1260```
1261
1262## PhotoType
1263
1264Enumerates media file types.
1265
1266**Atomic service API**: This API can be used in atomic services since API version 12.
1267
1268**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
1269
1270| Name | Value  | Description  |
1271| ----- | ---- | ------ |
1272| IMAGE | 1    | Image.|
1273| VIDEO | 2    | Video.|
1274
1275## AlbumType
1276
1277Enumerates the album types.
1278
1279**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
1280
1281| Name  | Value  | Description          |
1282| ------ | ---- | -------------- |
1283| USER   | 0    | User album.    |
1284| SYSTEM | 1024 | System album.|
1285
1286## AlbumSubtype
1287
1288Enumerate the album subtypes.
1289
1290**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
1291
1292| Name         | Value        | Description      |
1293| ------------- | ---------- | ---------- |
1294| USER\_GENERIC | 1          | User album.|
1295| FAVORITE      | 1025       | Favorites.  |
1296| VIDEO         | 1026       | Video album.|
1297| IMAGE         | 1031       | Photo album.|
1298| ANY           | 2147483647 | Any album.|
1299