openharmony 鸿蒙 capi-oh-file-uri-h

2026-08-25 浏览 (1)

oh_file_uri.h

Overview

FileUri provides APIs for URI operations, including performing URI-path conversion, obtaining directory URIs, and verifying URIs.

File to include: <filemanagement/file_uri/oh_file_uri.h>

Library: libohfileuri.so

System capability: SystemCapability.FileManagement.AppFileService

Since: 12

Related module: fileUri

Summary

Functions

NameDescription
FileManagement_ErrCode OH_FileUri_GetUriFromPath(const char *path, unsigned int length, char **result)Converts the input path to the URI of the application.
In this process, Chinese characters and non-digit characters in the path are encoded into the corresponding ASCII code and concatenated to the URI.
FileManagement_ErrCode OH_FileUri_GetPathFromUri(const char *uri, unsigned int length, char **result)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)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)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)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 encoded into the corresponding ASCII code and concatenated to the URI.

System capability: SystemCapability.FileManagement.AppFileService

Since: 12

Parameters

NameDescription
const char *pathPointer to the path to convert.
unsigned int lengthLength of the path to convert.
char **resultDouble pointer to the URI obtained. You also need to use free() of the standard library to release the memory allocated.

Returns

TypeDescription
FileManagement_ErrCodeReturns a specific error code. For details, see FileManagement_ErrCode.
ERR_INVALID_PARAMETER 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 13900042 - Unknown error. This error is returned if the length of the converted URI is 0.
ERR_ENOMEM 13900011 - The memory allocation or copy fails.
ERR_OK 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

NameDescription
const char *uriPointer to the URI to convert.
unsigned int lengthLength of the URI to convert.
char **resultDouble pointer to the path obtained. You also need to use free() of the standard library to release the memory allocated.

Returns

TypeDescription
FileManagement_ErrCodeReturns a specific error code. For details, see FileManagement_ErrCode.
ERR_INVALID_PARAMETER 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 URI is inconsistent with the value of length.
ERR_UNKNOWN 13900042 - Unknown error. This error is returned if the length of the converted path is 0.
ERR_ENOMEM 13900011 - The memory allocation or copy fails.
ERR_OK 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

NameDescription
const char *uriPointer to the target URI.
unsigned int lengthLength of the URI, in bytes.
char **resultDouble pointer to the URI obtained. You also need to use free() of the standard library to release the memory allocated.

Returns

TypeDescription
FileManagement_ErrCodeReturns a specific error code. For details, see FileManagement_ErrCode.
ERR_INVALID_PARAMETER 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 URI is inconsistent with the value of length.
ERR_ENOMEM 13900011 - The memory allocation or copy fails.
ERR_ENOENT 13900002 - The file or directory does not exist.
ERR_UNKNOWN 13900042 - Unknown error. This error is returned if the length of the obtained directory URI is 0.
ERR_OK 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

NameDescription
const char *uriPointer to the URI to check.
unsigned int lengthLength of the URI to check.

Returns

TypeDescription
boolReturns 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

NameDescription
const char *uriPointer to the URI to obtain.
unsigned int lengthLength of the URI, in bytes.
char **resultDouble pointer to the file name obtained. You also need to use free() of the standard library to release the memory allocated.

Returns

TypeDescription
FileManagement_ErrCodeReturns a specific error code. For details, see FileManagement_ErrCode.
ERR_INVALID_PARAMETER 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 URI is inconsistent with the value of length.
4. The URI is in incorrect format.
ERR_ENOMEM 13900011 - The memory allocation or copy fails.
ERR_OK 0 - The API is called successfully.

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 js-apis-file-environment-sys

openharmony 鸿蒙 js-apis-file-fs

openharmony 鸿蒙 capi-clouddisk-clouddisk-pathinfo

openharmony 鸿蒙 capi-clouddisk-clouddisk-changesresult

openharmony 鸿蒙 capi-clouddisk-clouddisk-syncfolder

openharmony 鸿蒙 js-apis-fileShare

openharmony 鸿蒙 capi-fileio

openharmony 鸿蒙 js-apis-file-storage-statistics-sys

openharmony 鸿蒙 js-apis-file-cloudsyncmanager

openharmony 鸿蒙 js-apis-file-environment

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/G6I4hEA6