# Fileuri ## Overview **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. **System capability**: SystemCapability.FileManagement.AppFileService **Since**: 12 ## Summary ### Files | Name| Description| | -------- |---------| | [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.| ### Functions | API| Description| | -------- |--------| | [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.| | [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.| | [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.| | 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.| | [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.)| ## Function Description ### OH_FileUri_GetFullDirectoryUri() ``` FileManagement_ErrCode OH_FileUri_GetFullDirectoryUri (const char * uri, unsigned int length, char ** result ) ``` **Description** 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. **System capability**: SystemCapability.FileManagement.AppFileService **Since**: 12 **Parameters** | Name| Description| | -------- | -------- | | uri | Pointer to the target URI.| | length | Length of the URI, in bytes.| | result | Double pointer to the URI obtained. You also need to use **free()** of the standard library to release the memory allocated.| **Returns** Returns [FileManagement_ErrCode](_file_i_o.md#filemanagement_errcode). ### OH_FileUri_GetPathFromUri() ``` FileManagement_ErrCode OH_FileUri_GetPathFromUri (const char * uri, unsigned int length, char ** result ) ``` **Description** In 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. **System capability**: SystemCapability.FileManagement.AppFileService **Since**: 12 **Parameters** | Name| Description| | -------- | -------- | | uri | Pointer to the URI to convert.| | length | Length of the URI to convert.| | result | Double pointer to the path obtained. You also need to use **free()** of the standard library to release the memory allocated.| **Returns** Returns [FileManagement_ErrCode](_file_i_o.md#filemanagement_errcode). ### OH_FileUri_GetUriFromPath() ``` FileManagement_ErrCode OH_FileUri_GetUriFromPath (const char * path, unsigned int length, char ** result ) ``` **Description** 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. **System capability**: SystemCapability.FileManagement.AppFileService **Since**: 12 **Parameters** | Name| Description| | -------- | -------- | | path | Pointer to the path to convert.| | length | Length of the path to convert.| | result | Double pointer to the URI obtained. You also need to use **free()** of the standard library to release the memory allocated.| **Returns** Returns [FileManagement_ErrCode](_file_i_o.md#filemanagement_errcode). ### OH_FileUri_IsValidUri() ``` bool OH_FileUri_IsValidUri (const char * uri, unsigned int length ) ``` **Description** Checks 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. **System capability**: SystemCapability.FileManagement.AppFileService **Since**: 12 **Parameters** | Name| Description| | -------- | -------- | | uri | Pointer to the URI to check.| | length | Length of the URI to check.| **Returns** Returns **true** if the URI is valid; returns **false** otherwise. ### OH_FileUri_GetFileName() ``` FileManagement_ErrCode OH_FileUri_GetFileName (const char * uri, unsigned int length, char ** result ) ``` **Description** Obtains 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.) **System capability**: SystemCapability.FileManagement.AppFileService **Since**: 13 **Parameters** | Name| Description| | -------- |--------| | uri | Pointer to the URI.| | length | Length of the URI, in bytes.| | result | Double pointer to the file name obtained. You also need to use **free()** of the standard library to release the memory allocated.| **Returns** Returns [FileManagement_ErrCode](_file_i_o.md#filemanagement_errcode).