# oh_file_uri.h ## Overview FileUri provides APIs for URI operations, including performing URI-path conversion, obtaining directory URIs, and verifying URIs. **Library**: libohfileuri.so **System capability**: SystemCapability.FileManagement.AppFileService **Since**: 12 **Related module**: [fileUri](capi-fileuri.md) ## Summary ### Functions | Name| Description| | -- | -- | | [FileManagement_ErrCode OH_FileUri_GetUriFromPath(const char *path, unsigned int length, char **result)](#oh_fileuri_geturifrompath) | Converts the input path to the URI of the application.
In this process, Chinese characters and non-digit characters in the path are compiled into the corresponding ASCII code and concatenated to the URI.| | [FileManagement_ErrCode OH_FileUri_GetPathFromUri(const char *uri, unsigned int length, char **result)](#oh_fileuri_getpathfromuri) | Converts the URI to the corresponding sandbox path.
1. In this process, the ASCII code in the URI is decoded and then concatenated to the original position. If the URI generated by a non-system API contains special characters that cannot be decoded, the string will not be concatenated.
2. Since strings are replaced based on specific rules that may evolve with the system, and no verification is performed, the converted path may not be accessible.| | [FileManagement_ErrCode OH_FileUri_GetFullDirectoryUri(const char *uri, unsigned int length, char **result)](#oh_fileuri_getfulldirectoryuri) | 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.
If the file specified by the URI does not exist or the property fails to be obtained, an empty string is returned.| | [bool OH_FileUri_IsValidUri(const char *uri, unsigned int length)](#oh_fileuri_isvaliduri) | 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 OH_FileUri_GetFileName(const char *uri, unsigned int length, char **result)](#oh_fileuri_getfilename) | Obtains the file name based on the URI.
The ASCII code in the file name will be decoded and concatenated to the original position.| ## Function Description ### OH_FileUri_GetUriFromPath() ``` FileManagement_ErrCode OH_FileUri_GetUriFromPath(const char *path, unsigned int length, char **result) ``` **Description** Converts the input path to the URI of the application.
In this process, Chinese characters and non-digit characters in the path are compiled into the corresponding ASCII code and concatenated to the URI. **System capability**: SystemCapability.FileManagement.AppFileService **Since**: 12 **Parameters** | Name| Description| | -- | -- | | const char *path | Pointer to the path to convert.| | unsigned int length | Length of the path to convert.| | char **result | Double pointer to the URI obtained. You also need to use **free()** of the standard library to release the memory allocated.| **Returns** | Type| Description| | -- | -- | | [FileManagement_ErrCode](capi-error-code-h.md#filemanagement_errcode) | Returns a specific error code. For details, see [FileManagement_ErrCode](capi-error-code-h.md#filemanagement_errcode).
ERR_PARAMS 401 - The input parameter is invalid. Possible causes:
1. The **path** parameter is a null pointer.
2. The **result** parameter is a null pointer.
3. The length of the input path is inconsistent with the value of **length**.
[ERR_UNKNOWN](capi-error-code-h.md#filemanagement_errcode) 13900042 - An unknown error occurs. This error is returned if the length of the converted URI is 0.
[ERR_ENOMEM](capi-error-code-h.md#filemanagement_errcode) 13900011 - The memory allocation or copy fails.
[ERR_OK](capi-error-code-h.md#filemanagement_errcode) 0 - The API is called successfully.| ### OH_FileUri_GetPathFromUri() ``` FileManagement_ErrCode OH_FileUri_GetPathFromUri(const char *uri, unsigned int length, char **result) ``` **Description** Converts the URI to the corresponding sandbox path.
1. In this process, the ASCII code in the URI is decoded and then concatenated to the original position. If the URI generated by a non-system API contains special characters that cannot be decoded, the string will not be concatenated.
2. Since strings are replaced based on specific rules that may evolve with the system, and no verification is performed, the converted path may not be accessible. **System capability**: SystemCapability.FileManagement.AppFileService **Since**: 12 **Parameters** | Name| Description| | -- | -- | | const char *uri | Pointer to the URI to convert.| | unsigned int length | Length of the URI to convert.| | char **result | Double pointer to the path obtained. You also need to use **free()** of the standard library to release the memory allocated.| **Returns** | Type| Description| | -- | -- | | [FileManagement_ErrCode](capi-error-code-h.md#filemanagement_errcode) | Returns a specific error code. For details, see [FileManagement_ErrCode](capi-error-code-h.md#filemanagement_errcode).
{@link ERR_PARAMS} 401 - The input parameter is invalid. Possible causes:
1. The **uri** parameter is a null pointer.
2. The **result** parameter is a null pointer.
3. The length of the input path is inconsistent with the value of **length**.
[ERR_UNKNOWN](capi-error-code-h.md#filemanagement_errcode) 13900042 - An unknown error occurs. This error is returned if the length of the converted path is 0.
[ERR_ENOMEM](capi-error-code-h.md#filemanagement_errcode) 13900011 - The memory allocation or copy fails.
[ERR_OK](capi-error-code-h.md#filemanagement_errcode) 0 - The API is called successfully.| ### 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.
If the file specified by the URI does not exist or the property fails to be obtained, an empty string is returned. **System capability**: SystemCapability.FileManagement.AppFileService **Since**: 12 **Parameters** | Name| Description| | -- | -- | | const char *uri | Pointer to the target URI.| | unsigned int length | Length of the URI, in bytes.| | char **result | Double pointer to the URI obtained. You also need to use **free()** of the standard library to release the memory allocated.| **Returns** | Type| Description| | -- | -- | | [FileManagement_ErrCode](capi-error-code-h.md#filemanagement_errcode) | Returns a specific error code. For details, see [FileManagement_ErrCode](capi-error-code-h.md#filemanagement_errcode).
ERR_PARAMS 401 - The input parameter is invalid. Possible causes:
1. The **uri** parameter is a null pointer.
2. The **result** parameter is a null pointer.
3. The length of the input path is inconsistent with the value of **length**.
[ERR_ENOMEM](capi-error-code-h.md#filemanagement_errcode) 13900011 - The memory allocation or copy fails.
[ERR_ENOENT](capi-error-code-h.md#filemanagement_errcode) 13900002 - The file or directory does not exist.
[ERR_UNKNOWN](capi-error-code-h.md#filemanagement_errcode) 13900042 - An unknown error occurs. This error is returned if the length of the obtained directory URI is 0.
[ERR_OK](capi-error-code-h.md#filemanagement_errcode) 0 - The API is called successfully.| ### OH_FileUri_IsValidUri() ``` bool OH_FileUri_IsValidUri(const char *uri, unsigned int length) ``` **Description** 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. **System capability**: SystemCapability.FileManagement.AppFileService **Since**: 12 **Parameters** | Name| Description| | -- | -- | | const char *uri | Pointer to the URI to check.| | unsigned int length | Length of the URI to check.| **Returns** | Type| Description| | -- | -- | | bool | 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 URI. The ASCII code in the file name will be decoded and concatenated to the original position. **System capability**: SystemCapability.FileManagement.AppFileService **Since**: 13 **Parameters** | Name| Description| | -- | -- | | const char *uri | Pointer to the URI to obtain.| | unsigned int length | Length of the URI, in bytes.| | char **result | Double pointer to the file name obtained. You also need to use **free()** of the standard library to release the memory allocated.| **Returns** | Type| Description| | -- | -- | | [FileManagement_ErrCode](capi-error-code-h.md#filemanagement_errcode) | Returns a specific error code. For details, see [FileManagement_ErrCode](capi-error-code-h.md#filemanagement_errcode).
ERR_PARAMS 401 - The input parameter is invalid. Possible causes:
1. The **uri** parameter is a null pointer.
2. The **result** parameter is a null pointer.
3. The length of the input path is inconsistent with the value of **length**.
4. The URI is in incorrect format.
[ERR_ENOMEM](capi-error-code-h.md#filemanagement_errcode) 13900011 - The memory allocation or copy fails.
[ERR_OK](capi-error-code-h.md#filemanagement_errcode) 0 - The API is called successfully.|