1# @ohos.app.ability.dataUriUtils (DataUriUtils) 2 3The **DataUriUtils** module provides APIs to process URI objects. You can use the APIs to attach an ID to the end of a given URI and obtain, delete, or update the ID attached to the end of a given URI. 4 5> **NOTE** 6> 7> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8 9## Modules to Import 10 11```ts 12import dataUriUtils from '@ohos.app.ability.dataUriUtils'; 13``` 14 15## dataUriUtils.getId 16 17getId(uri: string): number 18 19Obtains the ID attached to the end of a given URI. 20 21**System capability**: SystemCapability.Ability.AbilityRuntime.Core 22 23**Parameters** 24 25| Name| Type | Mandatory| Description | 26| ---- | ------ | ---- | --------------------------- | 27| uri | string | Yes | Target URI object.| 28 29**Return value** 30 31| Type | Description | 32| ------ | ------------------------ | 33| number | ID obtained.| 34 35**Example** 36 37```ts 38try { 39 let id = dataUriUtils.getId('com.example.dataUriUtils/1221'); 40 console.info('get id: ${id}'); 41} catch(err) { 42 console.error('get id err ,check the uri ${err}'); 43} 44``` 45 46## dataUriUtils.attachId 47 48attachId(uri: string, id: number): string 49 50Attaches an ID to the end of a given URI. 51 52**System capability**: SystemCapability.Ability.AbilityRuntime.Core 53 54**Parameters** 55 56| Name| Type | Mandatory| Description | 57| ---- | ------ | ---- | --------------------------- | 58| uri | string | Yes | Target URI object.| 59| id | number | Yes | ID to be attached. | 60 61**Return value** 62 63| Type | Description | 64| ------ | --------------------- | 65| string | URI object with the ID attached.| 66 67**Example** 68 69```ts 70let id = 1122; 71try { 72 let uri = dataUriUtils.attachId( 73 'com.example.dataUriUtils', 74 id, 75 ); 76 console.info('attachId the uri is: ${uri}'); 77} catch (err) { 78 console.error('get id err ,check the uri ${err}'); 79} 80 81``` 82 83## dataUriUtils.deleteId 84 85deleteId(uri: string): string 86 87Deletes the ID from the end of a given URI. 88 89**System capability**: SystemCapability.Ability.AbilityRuntime.Core 90 91**Parameters** 92 93| Name| Type | Mandatory| Description | 94| ---- | ------ | ---- | --------------------------- | 95| uri | string | Yes | URI object from which the ID is to be deleted.| 96 97**Return value** 98 99| Type | Description | 100| ------ | ------------------- | 101| string | URI object with the ID deleted.| 102 103**Example** 104 105```ts 106try { 107 let uri = dataUriUtils.deleteId('com.example.dataUriUtils/1221'); 108 console.info('delete id with the uri is: ${uri}'); 109} catch(err) { 110 console.error('delete uri err, check the input uri ${err}'); 111} 112 113``` 114 115## dataUriUtils.updateId 116 117updateId(uri: string, id: number): string 118 119Updates the ID in a given URI. 120 121**System capability**: SystemCapability.Ability.AbilityRuntime.Core 122 123**Parameters** 124 125| Name| Type | Mandatory| Description | 126| ---- | ------ | ---- | ------------------- | 127| uri | string | Yes | Target URI object.| 128| id | number | Yes | New ID. | 129 130**Return value** 131 132| Type | Description | 133| ------ | --------------- | 134| string | URI object with the new ID.| 135 136**Example** 137 138```ts 139 140try { 141 let id = 1122; 142 let uri = dataUriUtils.updateId( 143 'com.example.dataUriUtils/1221', 144 id 145 ); 146} catch (err) { 147 console.error('delete uri err, check the input uri ${err}'); 148} 149``` 150 151