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