From 6f9fb9398bd5205bda2c24e6e73c6938ead8745d Mon Sep 17 00:00:00 2001 From: zhouzhichao Date: Mon, 18 Apr 2022 20:13:18 +0800 Subject: [PATCH] add js-apis-document.md Signed-off-by: zhouzhichao --- .../reference/apis/Readme-CN.md | 1 + .../reference/apis/js-apis-document.md | 131 ++++++++++++++++++ 2 files changed, 132 insertions(+) create mode 100644 zh-cn/application-dev/reference/apis/js-apis-document.md diff --git a/zh-cn/application-dev/reference/apis/Readme-CN.md b/zh-cn/application-dev/reference/apis/Readme-CN.md index 369346fadd..f834608513 100644 --- a/zh-cn/application-dev/reference/apis/Readme-CN.md +++ b/zh-cn/application-dev/reference/apis/Readme-CN.md @@ -84,6 +84,7 @@ - data/rdb/[resultSet (结果集)](js-apis-data-resultset.md) - 文件管理 + - [@ohos.document (文件交互)](js-apis-document.md) - [@ohos.environment (目录环境能力)](js-apis-environment.md) - [@ohos.fileio (文件管理)](js-apis-fileio.md) - [@ohos.fileManager (公共文件访问与管理)](js-apis-filemanager.md) diff --git a/zh-cn/application-dev/reference/apis/js-apis-document.md b/zh-cn/application-dev/reference/apis/js-apis-document.md new file mode 100644 index 0000000000..6e326bc35d --- /dev/null +++ b/zh-cn/application-dev/reference/apis/js-apis-document.md @@ -0,0 +1,131 @@ +# 文件交互 + +> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** +- 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 +- 本模块接口后续将废弃。不建议在OpenHarmony使用以下接口,调用以下接口将抛出异常。 +## 导入模块 + +```js +import document from '@ohos.document'; +``` + +## document.choose + +choose(type:string[]): Promise<string> + +通过文件管理器选择文件,异步返回文件URI,使用promise形式返回结果。 + +**系统能力**:SystemCapability.FileManagement.File.FileIO + +- 参数: + + | 参数名 | 类型 | 必填 | 说明 | + | ------ | ------ | ---- | ---------------------------- | + | type | string[] | 否 | 限定文件选择的类型 | + +- 返回值: + + | 类型 | 说明 | + | --------------------- | -------------- | + | Promise<string> | 异步返回文件URI(注:当前返回错误码) | + +- 示例: + + ```js + await document.choose(type); + ``` +## document.choose + +choose(callback:AsyncCallback<string>): void + +通过文件管理器选择文件,异步返回文件URI,使用callback形式返回结果。 + +**系统能力**:SystemCapability.FileManagement.File.FileIO + +- 参数: + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | --------------------------- | ---- | ---------------------------- | + | callback | AsyncCallback<string> | 是 | 异步获取对应文件URI(注:当前返回错误码) | + +- 示例: + + ```js + await document.choose(function(err, uri) { + //do something with uri + }); + ``` +## document.choose + +choose(type:string[], callback:AsyncCallback<string>): void + +通过文件管理器选择文件,异步返回文件URI,使用callback形式返回结果。 + +**系统能力**:SystemCapability.FileManagement.File.FileIO + +- 参数: + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | --------------------------- | ---- | ---------------------------- | + | type | string[] | 否 | 限定选择文件的类型 | + | callback | AsyncCallback<string> | 是 | 异步获取对应文件URI(注:当前返回错误码) | + +- 示例: + + ```js + await document.choose(type, function(err, uri) { + //do something with uri + }); + ``` + +## document.show + +show(url:string, type:string):Promise<number> + +异步打开URI对应的文件,使用promise形式返回结果。 + +**系统能力**:SystemCapability.FileManagement.File.FileIO + +- 参数: + + | 参数 | 类型 | 必填 | 说明 | + | ---- | ------ | ---- | ---------------------------- | + | uri | string | 是 | 待打开的文件URI | + | type | string | 是 | 待打开文件的类型 | + +- 返回值: + + | 类型 | 说明 | + | --------------------- | ------------ | + | Promise<void> | Promise回调返回void表示成功打开文件(注:当前返回错误码) | + +- 示例: + + ```js + await document.show(uri, type); + ``` + +## document.show + +show(url:string, type:string, callback:AsyncCallback<void>): void + +异步打开URI对应的文件,使用callback形式返回结果。 + +**系统能力**:SystemCapability.FileManagement.File.FileIO + +- 参数: + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | --------------------------- | ---- | ---------------------------- | + | uri | string | 是 | 待打开的文件URI | + | type | string | 是 | 待打开文件的类型 | + | callback | AsyncCallback<void> | 是 | 异步打开uri对应文件(注:当前返回错误码) | + +- 示例: + + ```js + await document.show(uri, type, function(err) { + //do something + }); + ``` + -- GitLab