The **request** module provides applications with basic upload, download, and background transmission agent capabilities.
The **request** module provides applications with basic upload, download, and background transmission agent capabilities.
...
@@ -34,8 +34,9 @@ var config = {
...
@@ -34,8 +34,9 @@ var config = {
The **cleartextTraffic** attribute is not involved during application development in the stage model.
The **cleartextTraffic** attribute is not involved during application development in the stage model.
The download server must support the HTTP HEAD method so that the size of the data to download can be obtained through **content-length**. Otherwise, the download task fails. If this is the case, you can check the failure cause through [on('fail')<sup>7+</sup>)](#onfail7).
The download server must support the HTTP HEAD method so that the size of the data to download can be obtained through **Content-length**. Otherwise, the download task fails. If this is the case, you can check the failure cause through [on('fail')<sup>7+</sup>](#onfail7).
Only HTTP requests are supported. HTTPS requests are not supported.
## Constants
## Constants
...
@@ -69,86 +70,93 @@ The download server must support the HTTP HEAD method so that the size of the da
...
@@ -69,86 +70,93 @@ The download server must support the HTTP HEAD method so that the size of the da
| SESSION_SUCCESSFUL<sup>7+</sup> | number | Yes| No| Successful download.|
| SESSION_SUCCESSFUL<sup>7+</sup> | number | Yes| No| Successful download.|
Uploads files. This API uses a promise to return the result.
Uploads files. This API uses a promise to return the result.
> **NOTE**
>
> This API is supported since API version 9 and is deprecated since API version 9. You are advised to use [request.uploadFile<sup>9+</sup>](#requestuploadfile9).
console.error('Failed to request the upload. Cause: '+JSON.stringify(err));
console.error('Failed to request the upload. Cause: '+JSON.stringify(err));
return;
return;
...
@@ -341,10 +344,10 @@ For details about the error codes, see [Upload and Download Error Codes](../erro
...
@@ -341,10 +344,10 @@ For details about the error codes, see [Upload and Download Error Codes](../erro
});
});
```
```
## UploadTask
## UploadTask
Implements file uploads. Before using any APIs of this class, you must obtain an **UploadTask** object.
Implements file uploads. Before using any APIs of this class, you must obtain an **UploadTask** object through [request.uploadFile<sup>9+</sup>](#requestuploadfile9) in promise mode or [request.uploadFile<sup>9+</sup>](#requestuploadfile9-1) in callback mode.
### on('progress')
### on('progress')
...
@@ -359,10 +362,10 @@ Subscribes to an upload event. This API uses an asynchronous callback to return
...
@@ -359,10 +362,10 @@ Subscribes to an upload event. This API uses an asynchronous callback to return
**Parameters**
**Parameters**
| Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| type | string | Yes| Type of the event to subscribe to. The value is **'progress'** (upload progress).|
| type | string | Yes| Type of the event to subscribe to. The value is **'progress'** (upload progress).|
| callback | function | Yes| Callback for the upload progress event.|
| callback | function | Yes| Callback for the upload progress event.|
Parameters of the callback function
Parameters of the callback function
...
@@ -374,7 +377,6 @@ Subscribes to an upload event. This API uses an asynchronous callback to return
...
@@ -374,7 +377,6 @@ Subscribes to an upload event. This API uses an asynchronous callback to return
@@ -428,10 +429,10 @@ Subscribes to an upload event. This API uses an asynchronous callback to return
...
@@ -428,10 +429,10 @@ Subscribes to an upload event. This API uses an asynchronous callback to return
**Parameters**
**Parameters**
| Name| Type| Mandatory| Description|
| 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.|
| 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 | Callback<Array<TaskState>> | Yes| Callback used to return the result.|
| callback | Callback<Array<TaskState>> | Yes| Callback used to return the result.|
Parameters of the callback function
Parameters of the callback function
...
@@ -442,7 +443,6 @@ Subscribes to an upload event. This API uses an asynchronous callback to return
...
@@ -442,7 +443,6 @@ Subscribes to an upload event. This API uses an asynchronous callback to return
@@ -539,10 +537,10 @@ Unsubscribes from an upload event. This API uses an asynchronous callback to ret
...
@@ -539,10 +537,10 @@ Unsubscribes from an upload event. This API uses an asynchronous callback to ret
**Parameters**
**Parameters**
| Name| Type| Mandatory| Description|
| 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.|
| 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 | Callback<Array<TaskState>> | No| Callback used to return the result.|
| callback | Callback<Array<TaskState>> | No| Callback used to return the result.|
Parameters of the callback function
Parameters of the callback function
...
@@ -553,7 +551,6 @@ Unsubscribes from an upload event. This API uses an asynchronous callback to ret
...
@@ -553,7 +551,6 @@ Unsubscribes from an upload event. This API uses an asynchronous callback to ret
@@ -586,15 +577,14 @@ Removes this upload task. This API uses a promise to return the result.
...
@@ -586,15 +577,14 @@ Removes this upload task. This API uses a promise to return the result.
**Return value**
**Return value**
| Type| Description|
| Type| Description|
| -------- | -------- |
| -------- | -------- |
| Promise<boolean> | Promise used to return the result. It returns **true** if the operation is successful and returns **false** otherwise.|
| Promise<boolean> | Promise used to return the task removal result. It returns **true** if the operation is successful and returns **false** otherwise.|
@@ -657,14 +646,13 @@ Deletes this upload task. This API uses a promise to return the result.
...
@@ -657,14 +646,13 @@ Deletes this upload task. This API uses a promise to return the result.
**Return value**
**Return value**
| Type| Description|
| Type| Description|
| -------- | -------- |
| -------- | -------- |
| Promise<boolean> | Promise used to return the task deletion result. It returns **true** if the operation is successful and returns **false** otherwise.|
| Promise<boolean> | Promise used to return the task removal result. It returns **true** if the operation is successful and returns **false** otherwise.|
@@ -746,7 +736,7 @@ Deletes this upload task. This API uses an asynchronous callback to return the r
...
@@ -746,7 +736,7 @@ Deletes this upload task. This API uses an asynchronous callback to return the r
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| filename | string | Yes| File name in the header when **multipart** is used.|
| filename | string | Yes| File name in the header when **multipart** is used.|
| name | string | Yes| Name of a form item when **multipart** is used. The default value is **file**.|
| name | string | Yes| Name of a form item when **multipart** is used. The default value is **file**.|
| uri | string | Yes| Local path for storing files.<br>The **dataability** and **internal** protocol types are supported. However, the **internal** protocol type supports only temporary directories. Below are examples:<br>dataability:///com.domainname.dataability.persondata/person/10/file.txt<br>internal://cache/path/to/file.txt |
| uri | string | Yes| Local path for storing files.<br>The **dataability** and **internal** protocol types are supported. However, the **internal** protocol type supports only temporary directories. Below are examples:<br>dataability:///com.domainname.dataability.persondata/person/10/file.txt<br><br>internal://cache/path/to/file.txt |
| type | string | Yes| Type of the file content. By default, the type is obtained based on the extension of the file name or URI.|
| type | string | Yes| Type of the file content. By default, the type is obtained based on the extension of the file name or URI.|
...
@@ -761,40 +751,43 @@ Deletes this upload task. This API uses an asynchronous callback to return the r
...
@@ -761,40 +751,43 @@ Deletes this upload task. This API uses an asynchronous callback to return the r
Downloads files. This API uses a promise to return the result.
Downloads files. This API uses a promise to return the result.
> **NOTE**
>
> This API is supported since API version 9 and is deprecated since API version 9. You are advised to use [request.downloadFile<sup>9+</sup>](#requestdownloadfile9).
console.error('Failed to request the download. Cause: '+JSON.stringify(err));
console.error('Failed to request the download. Cause: '+JSON.stringify(err));
...
@@ -1003,7 +991,7 @@ For details about the error codes, see [Upload and Download Error Codes](../erro
...
@@ -1003,7 +991,7 @@ For details about the error codes, see [Upload and Download Error Codes](../erro
## DownloadTask
## DownloadTask
Implements file downloads.
Implements file downloads. Before using any APIs of this class, you must obtain a **DownloadTask** object through [request.downloadFile<sup>9+</sup>](#requestdownloadfile9) in promise mode or [request.downloadFile<sup>9+</sup>](#requestdownloadfile9-1) in callback mode.
### on('progress')
### on('progress')
...
@@ -1018,10 +1006,10 @@ Subscribes to a download event. This API uses an asynchronous callback to return
...
@@ -1018,10 +1006,10 @@ Subscribes to a download event. This API uses an asynchronous callback to return
**Parameters**
**Parameters**
| Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| type | string | Yes| Type of the event to subscribe to. The value is **'progress'** (download progress).|
| type | string | Yes| Type of the event to subscribe to. The value is **'progress'** (download progress).|
| callback | function | Yes| Callback for the download progress event.|
| callback | function | Yes| Callback for the download progress event.|
Parameters of the callback function
Parameters of the callback function
...
@@ -1033,7 +1021,6 @@ Subscribes to a download event. This API uses an asynchronous callback to return
...
@@ -1033,7 +1021,6 @@ Subscribes to a download event. This API uses an asynchronous callback to return
@@ -1661,14 +1607,13 @@ Queries this download task. This API uses an asynchronous callback to return the
...
@@ -1661,14 +1607,13 @@ Queries this download task. This API uses an asynchronous callback to return the
**Parameters**
**Parameters**
| Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback<[DownloadInfo](#downloadinfo7)> | Yes| Callback used to return the download task information.|
| callback | AsyncCallback<[DownloadInfo](#downloadinfo7)> | Yes| Callback used to return the download task information.|
**Example**
**Example**
```js
```js
letdownloadTask;
downloadTask.query((err,downloadInfo)=>{
downloadTask.getTaskInfo((err,downloadInfo)=>{
if(err){
if(err){
console.error('Failed to query the download mimeType. Cause:'+JSON.stringify(err));
console.error('Failed to query the download mimeType. Cause:'+JSON.stringify(err));
}else{
}else{
...
@@ -1678,11 +1623,15 @@ Queries this download task. This API uses an asynchronous callback to return the
...
@@ -1678,11 +1623,15 @@ Queries this download task. This API uses an asynchronous callback to return the
```
```
### getTaskMimeType<sup>9+</sup>
### queryMimeType<sup>(deprecated)</sup>
getTaskMimeType(): Promise<string>
queryMimeType(): Promise<string>
Obtains the **MimeType** of this download task. This API uses a promise to return the result.
Queries the **MimeType** of this download task. This API uses a promise to return the result.
> **NOTE**
>
> This API is supported since API version 7 and is deprecated since API version 9. You are advised to use [getTaskMimeType<sup>9+</sup>](#gettaskmimetype9).
Obtains the **MimeType** of this download task. This API uses an asynchronous callback to return the result.
Queries the **MimeType** of this download task. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> This API is supported since API version 7 and is deprecated since API version 9. You are advised to use [getTaskMimeType<sup>9+</sup>](#gettaskmimetype9-1).