• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.request (Upload and Download) (System API)
2
3The **request** module provides applications with basic upload, download, and background transmission agent capabilities.
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8>
9> This topic describes only system APIs provided by the module. For details about its public APIs, see [@ohos.request](js-apis-request.md).
10
11
12## Modules to Import
13
14
15```js
16import { request } from '@kit.BasicServicesKit';
17```
18
19
20## Filter<sup>10+</sup>
21
22Defines the filter criteria.
23
24**System capability**: SystemCapability.Request.FileTransferAgent
25
26| Name| Type| Mandatory| Description|
27| -------- | -------- | -------- | -------- |
28| bundle | string | No| Bundle name of the application.<br>**System API**: This is a system API.|
29
30
31## TaskInfo<sup>10+</sup>
32
33Defines the data structure of the task information for query. The fields available vary depending on the query types: common query and system query.
34
35**System capability**: SystemCapability.Request.FileTransferAgent
36
37| Name| Type| Mandatory| Description|
38| -------- | -------- | -------- | -------- |
39| uid | string | No| UID of the application. It is only available for query by system applications.<br>**System API**: This is a system API.|
40| bundle | string | No| Bundle name of the application. It is only available for query by system applications.<br>**System API**: This is a system API.|
41
42## Notification<sup>15+</sup>
43
44Describes the custom information of the notification bar.
45
46**Required permissions**: ohos.permission.REQUEST_DISABLE_NOTIFICATION
47
48**System capability**: SystemCapability.Request.FileTransferAgent
49
50
51
52| Name| Type| Mandatory| Description                                                                     |
53| -------- | -------- | -------- |-------------------------------------------------------------------------|
54| disable<sup>20+</sup> | boolean | No| Whether to disable the display of the notification bar. The value **true** means to disable the display of the notification bar; **false** means the opposite.<br>Default value: **false**.<br>**System API**: This is a system API.|
55
56## request.agent.query<sup>10+</sup>
57
58query(id: string, callback: AsyncCallback&lt;TaskInfo&gt;): void
59
60Queries a task details based on the task ID. This API uses an asynchronous callback to return the result.
61
62**Required permissions**: ohos.permission.DOWNLOAD_SESSION_MANAGER or ohos.permission.UPLOAD_SESSION_MANAGER
63
64**System capability**: SystemCapability.Request.FileTransferAgent
65
66**System API**: This is a system API.
67
68**Parameters**
69
70| Name| Type                                          | Mandatory| Description|
71|----------------------------------------------| -------- | -------- | -------- |
72| id | string                                       | Yes| Task ID.|
73| callback | AsyncCallback&lt;[TaskInfo](#taskinfo10)&gt; | Yes| Callback used to return task details.|
74
75**Error codes**
76
77For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Upload and Download Error Codes](errorcode-request.md).
78
79| ID| Error Message|
80| -------- | -------- |
81| 201 | permission denied. |
82| 202 | permission verification failed, application which is not a system application uses system API. |
83| 401 | parameter error. Possible causes: 1. Missing mandatory parameters. 2. Incorrect parameter type. |
84| 13400003 | task service ability error. |
85| 21900006 | task not found. |
86
87**Example**
88
89  ```ts
90  import { BusinessError } from '@kit.BasicServicesKit';
91
92  request.agent.query("123456", (err: BusinessError, taskInfo: request.agent.TaskInfo) => {
93    if (err) {
94      console.error(`Failed to query a upload task, Code: ${err.code}, message: ${err.message}`);
95      return;
96    }
97    console.info(`Succeeded in querying a upload task. result: ${taskInfo.uid}`);
98  });
99  ```
100
101
102## request.agent.query<sup>10+</sup>
103
104query(id: string): Promise&lt;TaskInfo&gt;
105
106Queries a task details based on the task ID. This API uses a promise to return the result.
107
108**Required permissions**: ohos.permission.DOWNLOAD_SESSION_MANAGER or ohos.permission.UPLOAD_SESSION_MANAGER
109
110**System capability**: SystemCapability.Request.FileTransferAgent
111
112**System API**: This is a system API.
113
114**Parameters**
115
116| Name| Type| Mandatory| Description|
117| -------- | -------- | -------- | -------- |
118| id | string | Yes| Task ID.|
119
120**Return value**
121
122| Type                                    | Description                     |
123|----------------------------------------| ------------------------- |
124| Promise&lt;[TaskInfo](#taskinfo10)&gt; | Promise Promise used to return task details.|
125
126**Error codes**
127
128For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Upload and Download Error Codes](errorcode-request.md).
129
130| ID| Error Message|
131| -------- | -------- |
132| 201 | permission denied. |
133| 202 | permission verification failed, application which is not a system application uses system API. |
134| 401 | parameter error. Possible causes: 1. Missing mandatory parameters. 2. Incorrect parameter type. |
135| 13400003 | task service ability error. |
136| 21900006 | task not found. |
137
138**Example**
139
140  ```ts
141  import { BusinessError } from '@kit.BasicServicesKit';
142
143  request.agent.query("123456").then((taskInfo: request.agent.TaskInfo) => {
144    console.info(`Succeeded in querying a upload task. result: ${taskInfo.uid}`);
145  }).catch((err: BusinessError) => {
146    console.error(`Failed to query a upload task, Code: ${err.code}, message: ${err.message}`);
147  });
148  ```
149