js-apis-DataUriUtils.md 2.3 KB
Newer Older
W
wusongqing 已提交
1 2 3 4 5 6 7 8
# DataUriUtils Module

## Modules to Import

```js
import dataUriUtils from '@ohos.ability.dataUriUtils';
```

W
wusongqing 已提交
9
## dataUriUtils.getId
W
wusongqing 已提交
10

W
wusongqing 已提交
11
getId(uri: string): number
W
wusongqing 已提交
12

W
wusongqing 已提交
13
Obtains the ID attached to the end of a given URI.
W
wusongqing 已提交
14

W
wusongqing 已提交
15
**Parameters**
W
wusongqing 已提交
16 17


W
wusongqing 已提交
18 19 20
| Name| Type| Mandatory| Description|
| ---- | ------ | ---- | --------------------------- |
| uri  | string | Yes| URI object from which the ID is to be obtained.|
W
wusongqing 已提交
21

W
wusongqing 已提交
22 23 24 25
**Return value**
| Type| Description|
| ------ | ------------------------ |
| number | ID obtained from the URI object.|
W
wusongqing 已提交
26

W
wusongqing 已提交
27
**Example**
W
wusongqing 已提交
28 29 30 31 32 33 34 35

```js
import dataUriUtils from '@ohos.ability.datauriutils'
dataUriUtils.getIdSync("com.example.dataUriUtils/1221")
```



W
wusongqing 已提交
36
## dataUriUtils.attachId
W
wusongqing 已提交
37

W
wusongqing 已提交
38
attachId(uri: string, id: number): string
W
wusongqing 已提交
39

W
wusongqing 已提交
40
Attaches an ID to the end of a given URI.
W
wusongqing 已提交
41

W
wusongqing 已提交
42
**Parameters**
W
wusongqing 已提交
43 44


W
wusongqing 已提交
45 46 47 48
| Name| Type| Mandatory| Description|
| ---- | ------ | ---- | --------------------------- |
| uri  | string | Yes| URI object to which an ID is to be attached.|
| id   | number | Yes| ID to be attached.|
W
wusongqing 已提交
49

W
wusongqing 已提交
50 51 52 53
**Return value**
| Type| Description|
| ------ | --------------------- |
| string | URI object with the ID attached.|
W
wusongqing 已提交
54

W
wusongqing 已提交
55
**Example**
W
wusongqing 已提交
56 57 58 59 60 61 62 63 64 65 66 67

```js
import dataUriUtils from '@ohos.ability.datauriutils'
var idint = 1122;
dataUriUtils.attachId(
    "com.example.dataUriUtils"
	idint,
)
```



W
wusongqing 已提交
68
## dataUriUtils.deleteId
W
wusongqing 已提交
69

W
wusongqing 已提交
70
deleteId(uri: string): string
W
wusongqing 已提交
71

W
wusongqing 已提交
72
Deletes the ID from the end of a given URI.
W
wusongqing 已提交
73

W
wusongqing 已提交
74
**Parameters**
W
wusongqing 已提交
75

W
wusongqing 已提交
76 77 78
| Name| Type| Mandatory| Description|
| ---- | ------ | ---- | --------------------------- |
| uri  | string | Yes| URI object from which the ID is to be deleted.|
W
wusongqing 已提交
79

W
wusongqing 已提交
80 81 82 83
**Return value**
| Type| Description|
| ------ | ------------------- |
| string | URI object with the ID deleted.|
W
wusongqing 已提交
84

W
wusongqing 已提交
85
**Example**
W
wusongqing 已提交
86 87 88 89 90 91 92 93

```js
import dataUriUtils from '@ohos.ability.datauriutils'
dataUriUtils.deleteId("com.example.dataUriUtils/1221")
```



W
wusongqing 已提交
94
## dataUriUtils.updateId
W
wusongqing 已提交
95

W
wusongqing 已提交
96
updateId(uri: string, id: number): string
W
wusongqing 已提交
97

W
wusongqing 已提交
98
Updates the ID in a given URI.
W
wusongqing 已提交
99

W
wusongqing 已提交
100
**Parameters**
W
wusongqing 已提交
101

W
wusongqing 已提交
102 103 104 105
| Name| Type| Mandatory| Description|
| ---- | ------ | ---- | ------------------- |
| uri  | string | Yes| URI object to be updated.|
| id   | number | Yes| New ID.|
W
wusongqing 已提交
106

W
wusongqing 已提交
107 108 109 110
**Return value**
| Type| Description|
| ------ | --------------- |
| string | URI object with the new ID.|
W
wusongqing 已提交
111

W
wusongqing 已提交
112
**Example**
W
wusongqing 已提交
113 114 115 116 117 118 119 120 121

```js
import dataUriUtils from '@ohos.ability.datauriutils'
var idint = 1122;
dataUriUtils.updateId(
    "com.example.dataUriUtils"
	idint,
)
```