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 47 48## dataUriUtils.attachId 49 50attachId(uri: string, id: number): string 51 52Attaches an ID to the end of a given URI. 53 54**System capability**: SystemCapability.Ability.AbilityRuntime.Core 55 56**Parameters** 57 58| Name| Type | Mandatory| Description | 59| ---- | ------ | ---- | --------------------------- | 60| uri | string | Yes | Target URI object.| 61| id | number | Yes | ID to be attached. | 62 63**Return value** 64 65| Type | Description | 66| ------ | --------------------- | 67| string | URI object with the ID attached.| 68 69**Example** 70 71```ts 72let id = 1122; 73try { 74 let uri = dataUriUtils.attachId( 75 'com.example.dataUriUtils', 76 id, 77 ); 78 console.info('attachId the uri is: ${uri}'); 79} catch (err) { 80 console.error('get id err ,check the uri ${err}'); 81} 82 83``` 84 85 86 87## dataUriUtils.deleteId 88 89deleteId(uri: string): string 90 91Deletes the ID from the end of a given URI. 92 93**System capability**: SystemCapability.Ability.AbilityRuntime.Core 94 95**Parameters** 96 97| Name| Type | Mandatory| Description | 98| ---- | ------ | ---- | --------------------------- | 99| uri | string | Yes | URI object from which the ID is to be deleted.| 100 101**Return value** 102 103| Type | Description | 104| ------ | ------------------- | 105| string | URI object with the ID deleted.| 106 107**Example** 108 109```ts 110try { 111 let uri = dataUriUtils.deleteId('com.example.dataUriUtils/1221'); 112 console.info('delete id with the uri is: ${uri}'); 113} catch(err) { 114 console.error('delete uri err, check the input uri ${err}'); 115} 116 117``` 118 119 120 121## dataUriUtils.updateId 122 123updateId(uri: string, id: number): string 124 125Updates the ID in a given URI. 126 127**System capability**: SystemCapability.Ability.AbilityRuntime.Core 128 129**Parameters** 130 131| Name| Type | Mandatory| Description | 132| ---- | ------ | ---- | ------------------- | 133| uri | string | Yes | Target URI object.| 134| id | number | Yes | New ID. | 135 136**Return value** 137 138| Type | Description | 139| ------ | --------------- | 140| string | URI object with the new ID.| 141 142**Example** 143 144```ts 145 146try { 147 let id = 1122; 148 let uri = dataUriUtils.updateId( 149 'com.example.dataUriUtils/1221', 150 id 151 ); 152} catch (err) { 153 console.error('delete uri err, check the input uri ${err}'); 154} 155``` 156