1# Removing Assets (ArkTS) 2 3## Available APIs 4 5You can use [remove(query: AssetMap)](../../reference/apis-asset-store-kit/js-apis-asset.md#assetremove), an asynchronous API, or [removeSync(query: AssetMap)](../../reference/apis-asset-store-kit/js-apis-asset.md#assetremovesync12), a synchronous API, to remove assets. If the asset alias is specified, the specified asset will be removed. If no asset alias is specified, all assets will be removed. 6 7The following table describes the attributes of **AssetMap** for removing 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| Attribute Name (Tag) | Value | Mandatory | Description | 14| --------------------- | ------------------------------------------------------------ | -------- | ------------------------------------------------ | 15| ALIAS | Type: Uint8Array<br>Length: 1-256 bytes | No | Asset alias, which uniquely identifies an asset. | 16| 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. | 17| REQUIRE_PASSWORD_SET | Type: Boolean | No | Whether the asset is accessible only when a lock screen password is set. The value **true** means the asset is accessible only when a lock screen password is set. The value **false** means that the asset can be accessed regardless of whether a lock screen password is set. | 18| 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. | 19| SYNC_TYPE | Type: number<br>Value range: see [SyncType](../../reference/apis-asset-store-kit/js-apis-asset.md#synctype)| No | Type of sync supported by the asset. | 20| IS_PERSISTENT | Type: Boolean | No | Whether to retain the asset when the application is uninstalled. The value **true** means to retain the asset even after the application is uninstalled. The value **false** means the opposite. | 21| 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.| 22| 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.| 23| 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.| 24| 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.| 25| 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.| 26| 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.| 27| 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.| 28| 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.| 29| 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.| 30| 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.| 31| 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.| 32| 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.| 33| REQUIRE_ATTR_ENCRYPTED<sup>14+</sup> | Type: Boolean| No| Whether to delete the encrypted data of service customized supplementary information. The value **true** means to delete the encrypted data of service customized supplementary information; the value **false** means to delete the non-encrypted data of service customized supplementary information. The default value is **false**.| 34| GROUP_ID<sup>18+</sup> | Type: Uint8Array<br>Length: 7-127 bytes| No| Group to which the asset to be removed belongs. By default, this parameter is not specified.| 35 36## Example 37 38> **NOTE** 39> 40> The **asset** module provides an asynchronous API and a synchronous API for removing 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). 41> 42> For details about how to remove an asset from a group, see [Removing an Asset from a Group](asset-js-group-access-control.md#removing-an-asset-from-a-group). 43 44Remove asset **demo_alias**. 45 46```typescript 47import { asset } from '@kit.AssetStoreKit'; 48import { util } from '@kit.ArkTS'; 49import { BusinessError } from '@kit.BasicServicesKit'; 50 51function stringToArray(str: string): Uint8Array { 52 let textEncoder = new util.TextEncoder(); 53 return textEncoder.encodeInto(str); 54} 55 56let query: asset.AssetMap = new Map(); 57query.set(asset.Tag.ALIAS, stringToArray('demo_alias')); // Specify the asset alias to remove a single asset. To remove all assets, leave the alias unspecified. 58try { 59 asset.remove(query).then(() => { 60 console.info(`Asset removed successfully.`); 61 }).catch((err: BusinessError) => { 62 console.error(`Failed to remove Asset. Code is ${err.code}, message is ${err.message}`); 63 }); 64} catch (error) { 65 let err = error as BusinessError; 66 console.error(`Failed to remove Asset. Code is ${err.code}, message is ${err.message}`); 67} 68``` 69