1# @ohos.request (上传下载)(系统接口) 2<!--Kit: Basic Services Kit--> 3<!--Subsystem: Request--> 4<!--Owner: @huaxin05--> 5<!--Designer: @hu-kai45--> 6<!--Tester: @murphy1984--> 7<!--Adviser: @fang-jinxu--> 8 9request部件主要给应用提供上传下载文件、后台传输代理的基础能力。 10 11> **说明:** 12> 13> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 14> 15> 当前界面仅包含本模块的系统接口,其他公开接口参见[@ohos.request](js-apis-request.md)。 16 17 18## 导入模块 19 20 21```js 22import { request } from '@kit.BasicServicesKit'; 23``` 24 25 26## Filter<sup>10+</sup> 27 28过滤条件。 29 30**系统能力**:SystemCapability.Request.FileTransferAgent 31 32| 名称 | 类型 | 只读 | 可选 | 说明 | 33|------|--------|----|----|-------------------------------| 34| bundle | string | 否 | 是 | 指定应用程序的包名,仅对系统应用开放。<br/>**系统接口**:此接口为系统接口。 | 35 36 37## TaskInfo<sup>10+</sup> 38 39查询结果的任务信息数据结构。提供普通查询和系统查询,两种字段的可见范围不同。 40 41**系统能力**:SystemCapability.Request.FileTransferAgent 42 43| 名称 | 类型 | 只读 | 可选 | 说明 | 44|------|--------|----|----|-------------------------------| 45| uid | string | 否 | 是 | 应用程序的UID,仅用于系统查询。<br/>**系统接口**:此接口为系统接口。| 46| bundle | string | 否 | 是 | 应用程序的包名,仅用于系统查询。<br/>**系统接口**:此接口为系统接口。| 47 48## Notification<sup>15+</sup> 49 50通知栏自定义信息。 51 52**需要权限**:ohos.permission.REQUEST_DISABLE_NOTIFICATION 53 54**系统能力**:SystemCapability.Request.FileTransferAgent 55 56 57| 名称 | 类型 | 只读 | 可选 | 说明 | 58|------|--------|----|----|-------------------------------| 59| disable<sup>20+</sup> | boolean | 否 | 是 | 是否关闭通知栏显示。true表示关闭通知栏显示,false表示不关闭通知栏显示。<br/>默认为false。<br/>**系统接口**:此接口为系统接口。 | 60 61## request.agent.query<sup>10+</sup> 62 63query(id: string, callback: AsyncCallback<TaskInfo>): void 64 65根据任务id查询任务的详细信息。使用callback异步回调。 66 67**需要权限**:ohos.permission.DOWNLOAD_SESSION_MANAGER 或 ohos.permission.UPLOAD_SESSION_MANAGER 68 69**系统能力**:SystemCapability.Request.FileTransferAgent 70 71**系统接口**:此接口为系统接口。 72 73**参数:** 74 75| 参数名 | 类型 | 必填 | 说明 | 76|----------------------------------------------| -------- | -------- | -------- | 77| id | string | 是 | 任务id。 | 78| callback | AsyncCallback<[TaskInfo](#taskinfo10)> | 是 | 回调函数,返回任务详细信息。 | 79 80**错误码:** 81 82以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[上传下载错误码](errorcode-request.md)。 83 84| 错误码ID | 错误信息 | 85| -------- | -------- | 86| 201 | permission denied. | 87| 202 | permission verification failed, application which is not a system application uses system API. | 88| 401 | parameter error. Possible causes: 1. Missing mandatory parameters. 2. Incorrect parameter type. | 89| 13400003 | task service ability error. | 90| 21900006 | task not found. | 91 92**示例:** 93 94 ```ts 95 import { BusinessError } from '@kit.BasicServicesKit'; 96 97 request.agent.query("123456", (err: BusinessError, taskInfo: request.agent.TaskInfo) => { 98 if (err) { 99 console.error(`Failed to query a upload task, Code: ${err.code}, message: ${err.message}`); 100 return; 101 } 102 console.info(`Succeeded in querying a upload task. result: ${taskInfo.uid}`); 103 }); 104 ``` 105 106 107## request.agent.query<sup>10+</sup> 108 109query(id: string): Promise<TaskInfo> 110 111根据任务id查询任务的详细信息。使用Promise异步回调。 112 113**需要权限**:ohos.permission.DOWNLOAD_SESSION_MANAGER 或 ohos.permission.UPLOAD_SESSION_MANAGER 114 115**系统能力**:SystemCapability.Request.FileTransferAgent 116 117**系统接口**:此接口为系统接口。 118 119**参数:** 120 121| 参数名 | 类型 | 必填 | 说明 | 122| -------- | -------- | -------- | -------- | 123| id | string | 是 | 任务id。 | 124 125**返回值:** 126 127| 类型 | 说明 | 128|----------------------------------------| ------------------------- | 129| Promise<[TaskInfo](#taskinfo10)> | Promise对象。返回任务详细信息的Promise对象。 | 130 131**错误码:** 132 133以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[上传下载错误码](errorcode-request.md)。 134 135| 错误码ID | 错误信息 | 136| -------- | -------- | 137| 201 | permission denied. | 138| 202 | permission verification failed, application which is not a system application uses system API. | 139| 401 | parameter error. Possible causes: 1. Missing mandatory parameters. 2. Incorrect parameter type. | 140| 13400003 | task service ability error. | 141| 21900006 | task not found. | 142 143**示例:** 144 145 ```ts 146 import { BusinessError } from '@kit.BasicServicesKit'; 147 148 request.agent.query("123456").then((taskInfo: request.agent.TaskInfo) => { 149 console.info(`Succeeded in querying a upload task. result: ${taskInfo.uid}`); 150 }).catch((err: BusinessError) => { 151 console.error(`Failed to query a upload task, Code: ${err.code}, message: ${err.message}`); 152 }); 153 ``` 154