diff --git a/en/application-dev/reference/apis/js-apis-request.md b/en/application-dev/reference/apis/js-apis-request.md index 272b2f8e21fe21adf0fac3fea2e1ea02c6581e96..45f0882a2cf0c151f04528c9e45271bf22ea1656 100644 --- a/en/application-dev/reference/apis/js-apis-request.md +++ b/en/application-dev/reference/apis/js-apis-request.md @@ -3,7 +3,6 @@ The **request** module provides applications with basic upload, download, and background transmission agent capabilities. > **NOTE** -> > 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. @@ -300,6 +299,48 @@ Parameters of the callback function ``` +### on('complete' | 'fail')9+ + + on(type:'complete' | 'fail', callback: Callback<Array<TaskState>>): void; + +Subscribes to an upload event. This API uses an asynchronous callback to return the result. + +**Required permissions**: ohos.permission.INTERNET + +**System capability**: SystemCapability.MiscServices.Upload + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| type | string | Yes| Type of the event to subscribe to. The value **'complete'** means the upload completion event, and **'fail'** means the upload failure event.| +| callback | function | Yes| Callback used to return the result.| + +Parameters of the callback function + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| taskstates | Array<[TaskState](#taskstate9)> | Yes| Upload result.| + +**Example** + + ```js + uploadTask.on('complete', function callback(taskStates) { + for (let i = 0; i < taskStates.length; i++ ) { + console.info("upOnComplete taskState:" + JSON.stringify(taskStates[i])); + } + } + ); + + uploadTask.on('fail', function callback(taskStates) { + for (let i = 0; i < taskStates.length; i++ ) { + console.info("upOnFail taskState:" + JSON.stringify(taskStates[i])); + } + } + ); + ``` + + ### off('progress') off(type: 'progress', callback?: (uploadedSize: number, totalSize: number) => void): void @@ -366,6 +407,47 @@ Parameters of the callback function ); ``` +### off('complete' | 'fail')9+ + + off(type:'complete' | 'fail', callback?: Callback<Array<TaskState>>): void; + +Unsubscribes from an upload event. This API uses an asynchronous callback to return the result. + +**Required permissions**: ohos.permission.INTERNET + +**System capability**: SystemCapability.MiscServices.Upload + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| type | string | Yes| Type of the event to subscribe to. The value **'complete'** means the upload completion event, and **'fail'** means the upload failure event.| +| callback | function | No| Callback used to return the result.| + +Parameters of the callback function + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| taskstates | Array<[TaskState](#taskstate9)> | Yes| Upload result.| + +**Example** + + ```js + uploadTask.off('complete', function callback(taskStates) { + for (let i = 0; i < taskStates.length; i++ ) { + console.info("upOnComplete taskState:" + JSON.stringify(taskStates[i])); + } + } + ); + + uploadTask.off('fail', function callback(taskStates) { + for (let i = 0; i < taskStates.length; i++ ) { + console.info("upOnFail taskState:" + JSON.stringify(taskStates[i])); + } + } + ); + ``` + ### remove @@ -445,6 +527,17 @@ Removes this upload task. This API uses an asynchronous callback to return the r | files | Array<[File](#file)> | Yes| List of files to upload, which is submitted through **multipart/form-data**.| | data | Array<[RequestData](#requestdata)> | Yes| Form data in the request body.| +## TaskState9+ + +**Required permissions**: ohos.permission.INTERNET + +**System capability**: SystemCapability.MiscServices.Upload + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| path | string | Yes| File path.| +| responseCode | number | Yes| Return value of an upload task.| +| message | string | Yes| Description of the upload task result.| ## File @@ -1120,7 +1213,7 @@ Resumes this download task. This API uses an asynchronous callback to return the | filePath7+ | string | No| Download path. (The default path is **'internal://cache/'**.)
- filePath:'workspace/test.txt': The **workspace** directory is created in the default path to store files.
- filePath:'test.txt': Files are stored in the default path.
- filePath:'workspace/': The **workspace** directory is created in the default path to store files.| | networkType | number | No| Network type allowed for download.
- NETWORK_MOBILE: 0x00000001
- NETWORK_WIFI: 0x00010000| | title | string | No| Title of the download session.| -| background | boolean | No| Whether to enable the background task notification. When this parameter is enabled, the download status is displayed in the notification panel.| +| background9+ | boolean | No| Whether to enable the background task notification. When this parameter is enabled, the download status is displayed in the notification panel.| ## DownloadInfo7+