• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Fileuri
2
3
4## Overview
5
6**Fileuri** provides the file Uniform Resource Identifier (URI) during cross-application file sharing. It can be used to generate URIs, obtain URI information (such as the path and file name), and verify the format. You are not advised to save the URI in the application because it will be unavailable after the optimization of conversion rules. You are advised to use APIs to generate the URI in real time.
7
8**System capability**: SystemCapability.FileManagement.AppFileService
9
10**Since**: 12
11
12
13## Summary
14
15
16### Files
17
18| Name| Description|
19| -------- |---------|
20| [oh_file_uri.h](oh__file__uri_8h.md) | Provides APIs for converting URIs to shared paths, generating the application URI, and obtaining the URI of the directory where the URI is located, facilitating URI access in the file sharing service.|
21
22
23### Functions
24
25| API| Description|
26| -------- |--------|
27| [FileManagement_ErrCode](_file_i_o.md#filemanagement_errcode) [OH_FileUri_GetUriFromPath](#oh_fileuri_geturifrompath)(const char *path, unsigned int length, char **result)| The URI of the application is generated based on the input path. When a path is converted to a URI, Chinese characters and non-digit characters in the path are compiled into the corresponding ASCII code and combined into the URI.|
28| [FileManagement_ErrCode](_file_i_o.md#filemanagement_errcode) [OH_FileUri_GetPathFromUri](#oh_fileuri_getpathfromuri)(const char *uri, unsigned int length, char **result) | Converts the URI to the corresponding sandbox path. 1. During URI-to-path conversion, the ASCII code in the URI is decoded and then concatenated to the original position. The URI generated by a non-system API may contain characters beyond the ASCII code parsing range. As a result, the string cannot be concatenated. 2. The conversion is performed based on the string replacement rule specified by the system (the rule may change with the system evolution). During the conversion, the path is not verified, so that the conversion result may not be accessible.|
29| [FileManagement_ErrCode](_file_i_o.md#filemanagement_errcode) [OH_FileUri_GetFullDirectoryUri](#oh_fileuri_getfulldirectoryuri)(const char *uri, unsigned int length, char **result) | Obtains the URI of the path. If the URI points to a file, the URI of the path is returned. If the URI points to a directory, the original string is returned without processing. If the file specified by the URI does not exist or the attribute fails to be obtained, an empty string is returned.|
30| bool [OH_FileUri_IsValidUri](#oh_fileuri_isvaliduri)(const char *uri, unsigned int length) | Checks whether the format of the input URI is correct. The system only checks whether the URI meets the format specifications defined by the system. The validity of the URI is not verified.|
31| [FileManagement_ErrCode](_file_i_o.md#filemanagement_errcode) [OH_FileUri_GetFileName](#oh_fileuri_getfilename)(const char *uri, unsigned int length, char **result) | Obtains the file name based on the given URI. (If the ASCII code exists, it will be decoded and then concatenated to the original position.)|
32## Function Description
33
34
35### OH_FileUri_GetFullDirectoryUri()
36
37```
38FileManagement_ErrCode OH_FileUri_GetFullDirectoryUri (const char * uri, unsigned int length, char ** result )
39```
40
41**Description**
42
43Obtains the URI of the path. If the URI points to a file, the URI of the path is returned. If the URI points to a directory, the original string is returned without processing. If the file specified by the URI does not exist or the attribute fails to be obtained, an empty string is returned.
44
45**System capability**: SystemCapability.FileManagement.AppFileService
46
47**Since**: 12
48
49**Parameters**
50
51| Name| Description|
52| -------- | -------- |
53| uri | Pointer to the target URI.|
54| length | Length of the URI, in bytes.|
55| result | Double pointer to the URI obtained. You also need to use **free()** of the standard library to release the memory allocated.|
56
57**Returns**
58
59Returns [FileManagement_ErrCode](_file_i_o.md#filemanagement_errcode).
60
61
62### OH_FileUri_GetPathFromUri()
63
64```
65FileManagement_ErrCode OH_FileUri_GetPathFromUri (const char * uri, unsigned int length, char ** result )
66```
67
68**Description**
69
70In the file sharing service, the sandbox path of the application sharing place is obtained through the URI. 1. During URI-to-path conversion, the ASCII code in the URI is decoded and then concatenated to the original position. The URI generated by a non-system API may contain characters beyond the ASCII code parsing range. As a result, the string cannot be concatenated. 2. The conversion is performed based on the string replacement rule specified by the system (the rule may change with the system evolution). During the conversion, the path is not verified, so that the conversion result may not be accessible.
71
72**System capability**: SystemCapability.FileManagement.AppFileService
73
74**Since**: 12
75
76**Parameters**
77
78| Name| Description|
79| -------- | -------- |
80| uri | Pointer to the URI to convert.|
81| length | Length of the URI to convert.|
82| result | Double pointer to the path obtained. You also need to use **free()** of the standard library to release the memory allocated.|
83
84**Returns**
85
86Returns [FileManagement_ErrCode](_file_i_o.md#filemanagement_errcode).
87
88
89### OH_FileUri_GetUriFromPath()
90
91```
92FileManagement_ErrCode OH_FileUri_GetUriFromPath (const char * path, unsigned int length, char ** result )
93```
94
95**Description**
96
97The URI of the application is generated based on the input path. When a path is converted to a URI, Chinese characters and non-digit characters in the path are compiled into the corresponding ASCII code and combined into the URI.
98
99**System capability**: SystemCapability.FileManagement.AppFileService
100
101**Since**: 12
102
103**Parameters**
104
105| Name| Description|
106| -------- | -------- |
107| path | Pointer to the path to convert.|
108| length | Length of the path to convert.|
109| result | Double pointer to the URI obtained. You also need to use **free()** of the standard library to release the memory allocated.|
110
111**Returns**
112
113Returns [FileManagement_ErrCode](_file_i_o.md#filemanagement_errcode).
114
115
116### OH_FileUri_IsValidUri()
117
118```
119bool OH_FileUri_IsValidUri (const char * uri, unsigned int length )
120```
121
122**Description**
123
124Checks whether the format of the input URI is correct. Only the basic format of the URI is verified. The validity of the URI is not verified.
125
126**System capability**: SystemCapability.FileManagement.AppFileService
127
128**Since**: 12
129
130**Parameters**
131
132| Name| Description|
133| -------- | -------- |
134| uri | Pointer to the URI to check.|
135| length | Length of the URI to check.|
136
137**Returns**
138
139Returns **true** if the URI is valid; returns **false** otherwise.
140
141### OH_FileUri_GetFileName()
142
143```
144FileManagement_ErrCode OH_FileUri_GetFileName (const char * uri, unsigned int length, char ** result )
145```
146
147**Description**
148
149Obtains the file name based on the given URI. (If the ASCII code exists in the file name, the ASCII code will be decoded and concatenated to the original position.)
150
151**System capability**: SystemCapability.FileManagement.AppFileService
152
153**Since**: 13
154
155**Parameters**
156
157| Name| Description|
158| -------- |--------|
159| uri | Pointer to the URI.|
160| length | Length of the URI, in bytes.|
161| result | Double pointer to the file name obtained. You also need to use **free()** of the standard library to release the memory allocated.|
162
163**Returns**
164
165Returns [FileManagement_ErrCode](_file_i_o.md#filemanagement_errcode).
166