1e41f4b71Sopenharmony_ci# Before You Start
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciAn application needs to obtain a **PhotoAccessHelper** instance before accessing or modifying the media data in an album. User personal data is involved in the **photoAccessHelper** module. Therefore, the application must also apply for the related read and write permissions from the user. Unless otherwise specified, the APIs of the **photoAccessHelper** module are used in **pages/index.ets** of the project or other customized .ets files.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci## Obtaining a PhotoAccessHelper Instance
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ciThe application needs to call [getPhotoAccessHelper](../../reference/apis-media-library-kit/js-apis-photoAccessHelper.md#photoaccesshelpergetphotoaccesshelper) to obtain a **PhotoAccessHelper** instance based on the application context. Then, the application can use the instance obtained to access or modify the media data (such as images and videos) in an album.
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci**How to Develop**
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci1. Import the **photoAccessHelper** module.
12e41f4b71Sopenharmony_ci2. Use **getContext** to obtain the application context.
13e41f4b71Sopenharmony_ci3. Obtain a **PhotoAccessHelper** instance.
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci```ts
16e41f4b71Sopenharmony_ciimport { photoAccessHelper } from '@kit.MediaLibraryKit';
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ci// The photoAccessHelper instance obtained here is a global object. Unless otherwise specified, the object obtained here is used in subsequent operations in this document. If an undefined error is reported, add the code snippet here.
19e41f4b71Sopenharmony_ciconst context = getContext(this);
20e41f4b71Sopenharmony_cilet phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context);
21e41f4b71Sopenharmony_ci```
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci## Requesting Permissions
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ciBefore requesting the permissions for the **PhotoAccessHelper** module, ensure that the [basic principles for using permissions](../../security/AccessToken/app-permission-mgmt-overview.md#basic-principles-for-using-permissions) are met. The following permissions are required.
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci| Permission                        | Description                                      | Authorization Mode  |
28e41f4b71Sopenharmony_ci| ------------------------------ | ------------------------------------------ | ---------- |
29e41f4b71Sopenharmony_ci| ohos.permission.READ_IMAGEVIDEO     | Allows an application to read images and videos in the media library.| user_grant |
30e41f4b71Sopenharmony_ci| ohos.permission.WRITE_IMAGEVIDEO    | Allows an application to read and write images and videos in the media library.| user_grant |
31e41f4b71Sopenharmony_ci
32e41f4b71Sopenharmony_ciThe required permissions must be authorized by the user. After adding the permissions in the **module.json5** file, use [abilityAccessCtrl.requestPermissionsFromUser](../../reference/apis-ability-kit/js-apis-abilityAccessCtrl.md#requestpermissionsfromuser9) to check whether the required permissions are granted by the user. If yes, the application can access the data. Otherwise, display a dialog box to request user authorization.
33e41f4b71Sopenharmony_ci
34e41f4b71Sopenharmony_ci**How to Develop**
35e41f4b71Sopenharmony_ci<!--RP1-->
36e41f4b71Sopenharmony_ci1. Request the required permissions via the ACL. For details, see [Requesting Restricted Permissions](../../security/AccessToken/declare-permissions-in-acl.md).
37e41f4b71Sopenharmony_ci<!--RP1End-->
38e41f4b71Sopenharmony_ci2. [Declare the required permissions in the **module.json5** file](../../security/AccessToken/declare-permissions.md).
39e41f4b71Sopenharmony_ci3. [Request user authorization](../../security/AccessToken/request-user-authorization.md).
40e41f4b71Sopenharmony_ci
41e41f4b71Sopenharmony_ci> **NOTE**
42e41f4b71Sopenharmony_ci>
43e41f4b71Sopenharmony_ci> Even if the user has granted the permission, the permission will still be checked before an API protected by the permission is called. The permission-granted status should not be persisted, because the user can revoke the permission through the system application **Settings**.
44