1# Updating an Asset (ArkTS) 2 3## Available APIs 4 5You can use [update(query: AssetMap, attributesToUpdate: AssetMap)](../../reference/apis-asset-store-kit/js-apis-asset.md#assetupdate), an asynchronous API, or [updateSync(query: AssetMap, attributesToUpdate: AssetMap)](../../reference/apis-asset-store-kit/js-apis-asset.md#assetupdatesync12), a synchronous API, to update an asset. 6 7The following table describes the attributes of **AssetMap** for updating an asset. 8 9>**NOTE** 10> 11>In the following table, the attributes starting with **DATA_LABEL** are custom asset attributes reserved for services. These attributes are not encrypted. Therefore, do not put personal data in these attributes. 12 13- Attributes of **AssetMap** in **query**: 14 15 | Attribute Name (Tag) | Attribute Content (Value) | Mandatory | Description | 16 | --------------------- | ------------------------------------------------------------ | -------- | ------------------------------------------------ | 17 | ALIAS | Type: Uint8Array<br>Length: 1-256 bytes | Yes | Asset alias, which uniquely identifies an asset. | 18 | ACCESSIBILITY | Type: number<br>Value range: see [Accessibility](../../reference/apis-asset-store-kit/js-apis-asset.md#accessibility)| No | Access control based on the lock screen status. | 19 | REQUIRE_PASSWORD_SET | Type: bool | No | Whether the asset is accessible only when a lock screen password is set. | 20 | AUTH_TYPE | Type: number<br>Value range: see [AuthType](../../reference/apis-asset-store-kit/js-apis-asset.md#authtype)| No | Type of user authentication required for accessing the asset. | 21 | SYNC_TYPE | Type: number<br>Value range: see [SyncType](../../reference/apis-asset-store-kit/js-apis-asset.md#synctype)| No | Asset sync type. | 22 | IS_PERSISTENT | Type: bool | No | Whether to retain the asset when the application is uninstalled. | 23 | DATA_LABEL_CRITICAL_1 | Type: Uint8Array<br>Length: 1-2048 bytes | No | Asset attribute information customized by the service with integrity protection.<br>**NOTE**: The data length is 1 to 512 bytes before API version 12.| 24 | DATA_LABEL_CRITICAL_2 | Type: Uint8Array<br>Length: 1-2048 bytes | No | Asset attribute information customized by the service with integrity protection.<br>**NOTE**: The data length is 1 to 512 bytes before API version 12.| 25 | DATA_LABEL_CRITICAL_3 | Type: Uint8Array<br>Length: 1-2048 bytes | No | Asset attribute information customized by the service with integrity protection.<br>**NOTE**: The data length is 1 to 512 bytes before API version 12.| 26 | DATA_LABEL_CRITICAL_4 | Type: Uint8Array<br>Length: 1-2048 bytes | No | Asset attribute information customized by the service with integrity protection.<br>**NOTE**: The data length is 1 to 512 bytes before API version 12.| 27 | DATA_LABEL_NORMAL_1 | Type: Uint8Array<br>Length: 1-2048 bytes | No | Asset attribute information customized by the service without integrity protection.<br>**NOTE**: The data length is 1 to 512 bytes before API version 12.| 28 | DATA_LABEL_NORMAL_2 | Type: Uint8Array<br>Length: 1-2048 bytes | No | Asset attribute information customized by the service without integrity protection.<br>**NOTE**: The data length is 1 to 512 bytes before API version 12.| 29 | DATA_LABEL_NORMAL_3 | Type: Uint8Array<br>Length: 1-2048 bytes | No | Asset attribute information customized by the service without integrity protection.<br>**NOTE**: The data length is 1 to 512 bytes before API version 12.| 30 | DATA_LABEL_NORMAL_4 | Type: Uint8Array<br>Length: 1-2048 bytes | No | Asset attribute information customized by the service without integrity protection.<br>**NOTE**: The data length is 1 to 512 bytes before API version 12.| 31 | DATA_LABEL_NORMAL_LOCAL_1<sup>12+</sup> | Type: Uint8Array<br>Length: 1-2048 bytes| No| Local attribute information about the asset. The value is assigned by the service without integrity protection and will not be synced.| 32 | DATA_LABEL_NORMAL_LOCAL_2<sup>12+</sup> | Type: Uint8Array<br>Length: 1-2048 bytes| No| Local attribute information about the asset. The value is assigned by the service without integrity protection and will not be synced.| 33 | DATA_LABEL_NORMAL_LOCAL_3<sup>12+</sup> | Type: Uint8Array<br>Length: 1-2048 bytes| No| Local attribute information about the asset. The value is assigned by the service without integrity protection and will not be synced.| 34 | DATA_LABEL_NORMAL_LOCAL_4<sup>12+</sup> | Type: Uint8Array<br>Length: 1-2048 bytes| No| Local attribute information about the asset. The value is assigned by the service without integrity protection and will not be synced.| 35 | REQUIRE_ATTR_ENCRYPTED<sup>14+</sup> | Type: bool| No| Whether to update the customized asset attribute information that is encrypted. By default, the unencrypted customized asset attribute information is updated.| 36 37- Attributes of **AssetMap** in **attributesToUpdate**: 38 39 | Attribute Name (Tag) | Attribute Content (Value) | Mandatory | Description | 40 | --------------------- | -------------------------------| -------- | ------------------------------- | 41 | SECRET | Type: Uint8Array<br>Length: 1-1024 bytes | No | New asset in plaintext. | 42 | DATA_LABEL_NORMAL_1 | Type: Uint8Array<br>Length: 1-2048 bytes | No | New asset attribute information customized by the service without integrity protection.<br>**NOTE**: The data length is 1 to 512 bytes before API version 12.| 43 | DATA_LABEL_NORMAL_2 | Type: Uint8Array<br>Length: 1-2048 bytes | No | New asset attribute information customized by the service without integrity protection.<br>**NOTE**: The data length is 1 to 512 bytes before API version 12.| 44 | DATA_LABEL_NORMAL_3 | Type: Uint8Array<br>Length: 1-2048 bytes | No | New asset attribute information customized by the service without integrity protection.<br>**NOTE**: The data length is 1 to 512 bytes before API version 12.| 45 | DATA_LABEL_NORMAL_4 | Type: Uint8Array<br>Length: 1-2048 bytes | No | New asset attribute information customized by the service without integrity protection.<br>**NOTE**: The data length is 1 to 512 bytes before API version 12.| 46 | DATA_LABEL_NORMAL_LOCAL_1<sup>12+</sup> | Type: Uint8Array<br>Length: 1-2048 bytes| No| Local attribute information about the new asset. The value is assigned by the service without integrity protection and will not be synced.| 47 | DATA_LABEL_NORMAL_LOCAL_2<sup>12+</sup> | Type: Uint8Array<br>Length: 1-2048 bytes| No| Local attribute information about the new asset. The value is assigned by the service without integrity protection and will not be synced.| 48 | DATA_LABEL_NORMAL_LOCAL_3<sup>12+</sup> | Type: Uint8Array<br>Length: 1-2048 bytes| No| Local attribute information about the new asset. The value is assigned by the service without integrity protection and will not be synced.| 49 | DATA_LABEL_NORMAL_LOCAL_4<sup>12+</sup> | Type: Uint8Array<br>Length: 1-2048 bytes| No| Local information about the new asset. The value is assigned by the service without integrity protection and will not be synced.| 50 51## Example 52 53> **NOTE** 54> 55> The **asset** module provides an asynchronous API and a synchronous API for updating an asset. The following uses the asynchronous API as an example. For more information about the APIs, see [Asset Store Service](../../reference/apis-asset-store-kit/js-apis-asset.md). 56 57Update asset **demo_alias** as follows: change the asset plaintext to **demo_pwd_new** and additional attribute to **demo_label_new**. 58 59```typescript 60import { asset } from '@kit.AssetStoreKit'; 61import { util } from '@kit.ArkTS'; 62import { BusinessError } from '@kit.BasicServicesKit'; 63 64function stringToArray(str: string): Uint8Array { 65 let textEncoder = new util.TextEncoder(); 66 return textEncoder.encodeInto(str); 67} 68 69let query: asset.AssetMap = new Map(); 70query.set(asset.Tag.ALIAS, stringToArray('demo_alias')); 71let attrsToUpdate: asset.AssetMap = new Map(); 72attrsToUpdate.set(asset.Tag.SECRET, stringToArray('demo_pwd_new')); 73attrsToUpdate.set(asset.Tag.DATA_LABEL_NORMAL_1, stringToArray('demo_label_new')); 74try { 75 asset.update(query, attrsToUpdate).then(() => { 76 console.info(`Asset updated successfully.`); 77 }).catch((err: BusinessError) => { 78 console.error(`Failed to update Asset. Code is ${err.code}, message is ${err.message}`); 79 }); 80} catch (error) { 81 let err = error as BusinessError; 82 console.error(`Failed to update Asset. Code is ${err.code}, message is ${err.message}`); 83} 84``` 85