1e41f4b71Sopenharmony_ci# Creating a Media Asset Using SaveButton
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThis topic walks you through on how to create an image using the **SaveButton** security component. When **SaveButton** is used to create a media asset, the caller does not need to have the ohos.permission.WRITE_IMAGEVIDEO permission. For details, see [SaveButton](../../reference/apis-arkui/arkui-ts/ts-security-components-savebutton.md).
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci**How to Develop**
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ci1. Set the attributes of the security component.
8e41f4b71Sopenharmony_ci2. Create a button with the security component.
9e41f4b71Sopenharmony_ci3. Use [MediaAssetChangeRequest.createImageAssetRequest](../../reference/apis-media-library-kit/js-apis-photoAccessHelper.md#createimageassetrequest11) and [PhotoAccessHelper.applyChanges](../../reference/apis-media-library-kit/js-apis-photoAccessHelper.md#applychanges11) to create an image asset.
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci```ts
12e41f4b71Sopenharmony_ciimport { photoAccessHelper } from '@kit.MediaLibraryKit';
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ci@Entry
15e41f4b71Sopenharmony_ci@Component
16e41f4b71Sopenharmony_cistruct Index {
17e41f4b71Sopenharmony_ci  @State message: string = 'Hello World'
18e41f4b71Sopenharmony_ci  @State saveButtonOptions: SaveButtonOptions = {
19e41f4b71Sopenharmony_ci    icon: SaveIconStyle.FULL_FILLED,
20e41f4b71Sopenharmony_ci    text: SaveDescription.SAVE_IMAGE,
21e41f4b71Sopenharmony_ci    buttonType: ButtonType.Capsule
22e41f4b71Sopenharmony_ci  } // Set the attributes of the security component.
23e41f4b71Sopenharmony_ci
24e41f4b71Sopenharmony_ci  build() {
25e41f4b71Sopenharmony_ci    Row() {
26e41f4b71Sopenharmony_ci      Column() {
27e41f4b71Sopenharmony_ci        Text(this.message)
28e41f4b71Sopenharmony_ci          .fontSize(50)
29e41f4b71Sopenharmony_ci          .fontWeight(FontWeight.Bold)
30e41f4b71Sopenharmony_ci        SaveButton(this.saveButtonOptions) // Create a security component.
31e41f4b71Sopenharmony_ci          .onClick(async (event, result: SaveButtonOnClickResult) => {
32e41f4b71Sopenharmony_ci             if (result == SaveButtonOnClickResult.SUCCESS) {
33e41f4b71Sopenharmony_ci               try {
34e41f4b71Sopenharmony_ci                 let context = getContext();
35e41f4b71Sopenharmony_ci                 let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context);
36e41f4b71Sopenharmony_ci                 // Ensure that the asset specified by fileUri exists.
37e41f4b71Sopenharmony_ci                 let fileUri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/test.jpg';
38e41f4b71Sopenharmony_ci                 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = photoAccessHelper.MediaAssetChangeRequest.createImageAssetRequest(context, fileUri);
39e41f4b71Sopenharmony_ci                 await phAccessHelper.applyChanges(assetChangeRequest);
40e41f4b71Sopenharmony_ci                 console.info('createAsset successfully, uri: ' + assetChangeRequest.getAsset().uri);
41e41f4b71Sopenharmony_ci               } catch (err) {
42e41f4b71Sopenharmony_ci                 console.error(`create asset failed with error: ${err.code}, ${err.message}`);
43e41f4b71Sopenharmony_ci               }
44e41f4b71Sopenharmony_ci             } else {
45e41f4b71Sopenharmony_ci               console.error('SaveButtonOnClickResult create asset failed');
46e41f4b71Sopenharmony_ci             }
47e41f4b71Sopenharmony_ci          })
48e41f4b71Sopenharmony_ci      }
49e41f4b71Sopenharmony_ci      .width('100%')
50e41f4b71Sopenharmony_ci    }
51e41f4b71Sopenharmony_ci    .height('100%')
52e41f4b71Sopenharmony_ci  }
53e41f4b71Sopenharmony_ci}
54e41f4b71Sopenharmony_ci```
55