The Request service provides third-party applications with the download and upload capabilities. With it, you can conveniently and efficiently use and manage download and upload services, including creating, removing, suspending, resuming, and querying download and upload tasks.
| download(config: DownloadConfig, callback: AsyncCallback\<DownloadTask>): void | Downloads files. This API uses an asynchronous callback to return the **DownloadTask** instance. You can then use the instance to perform operations on the download task, for example, adding listeners for the **progress**, **complete**, and **fail** events, or suspending, resuming, removing, and querying the download task. |
| download(config: DownloadConfig): Promise\<DownloadTask> | Downloads files. This API uses a promise to return the **DownloadTask** instance. You can then use the instance to perform operations on the download task, for example, adding listeners for the **progress**, **complete**, and **fail** events, or suspending, resuming, removing, and querying the download task. |
| upload(config: UploadConfig, callback: AsyncCallback\<UploadTask>): void | Uploads files. This API uses an asynchronous callback to return the **UploadTask** instance. You can then use the instance to perform operations on the upload task, for example, adding listeners for the **progress**, **headerReceive**, and **fail** events, or removing the upload task. |
| upload(config: UploadConfig): Promise\<UploadTask> | Uploads files. This API uses a promise to return the **UploadTask** instance. You can then use the instance to perform operations on the upload task, for example, adding listeners for the **progress**, **headerReceive**, and **fail** events, or removing the upload task. |
| download(context: BaseContext,config: DownloadConfig, callback: AsyncCallback\<DownloadTask>): void | Downloads files. This API uses an asynchronous callback to return the **DownloadTask** instance. You can then use the instance to perform operations on the download task, for example, adding listeners for the **progress**, **complete**, and **fail** events, or suspending, resuming, removing, and querying the download task. |
| download(context: BaseContext,config: DownloadConfig): Promise\<DownloadTask> | Downloads files. This API uses a promise to return the **DownloadTask** instance. You can then use the instance to perform operations on the download task, for example, adding listeners for the **progress**, **complete**, and **fail** events, or suspending, resuming, removing, and querying the download task. |
| upload(context: BaseContext,config: UploadConfig, callback: AsyncCallback\<UploadTask>): void | Uploads files. This API uses an asynchronous callback to return the **UploadTask** instance. You can then use the instance to perform operations on the upload task, for example, adding listeners for the **progress**, **headerReceive**, and **fail** events, or removing the upload task. |
| upload(context: BaseContext,config: UploadConfig): Promise\<UploadTask> | Uploads files. This API uses a promise to return the **UploadTask** instance. You can then use the instance to perform operations on the upload task, for example, adding listeners for the **progress**, **headerReceive**, and **fail** events, or removing the upload task. |
| on(type: 'progress', callback:(receivedSize: number, totalSize: number) => void): void | Enables listening for download task progress changes. This API uses a callback to return the download progress. If this API is called multiple times, the callback passed in the last call is used. |
| on(type: 'complete' l 'pause' l 'remove', callback:() => void): void | Enables listening for download states: **complete**, **pause**, and **remove**. This API uses a callback to return the result. If this API is called multiple times, the callback passed in the last call is used. |
| on(type: 'fail', callback:(error: number) => void): void | Enables listening for the download failure event. This API uses a callback to return the error code. If this API is called multiple times, the callback passed in the last call is used. |
| off(type: 'progress', callback?:(receivedSize: number, totalSize: number) => void): void | Disables listening for download task progress changes. This API uses a callback to return the result. |
| off(type: 'complete' l 'pause' l 'remove', callback?:() => void): void | Disables listening for download states: **complete**, **pause**, and **remove**. This API uses a callback to return the result. |
| off(type: 'fail', callback?:(error: number) => void): void | Disables listening for the download failure event. This API uses a callback to return the result. |
| remove(): Promise\<boolean> | Removes this download task. This API uses a promise to return the result. |
| remove(callback: AsyncCallback\<boolean>): void | Removes this download task. This API uses an asynchronous callback to return the result. |
| pause(): Promise\<boolean> | Pauses this download task. This API uses a promise to return the result. |
| pause(callback: AsyncCallback\<boolean>): void | Pauses this download task. This API uses an asynchronous callback to return the result. |
| resume(): Promise\<boolean> | Resumes this download task. This API uses a promise to return the result. |
| resume(callback: AsyncCallback\<boolean>): void | Resumes this download task. This API uses an asynchronous callback to return the result. |
| query(): Promise\<DownloadInfo> | Queries download tasks. This API uses a promise to return the **DownloadInfo** object. |
| query(callback: AsyncCallback\<DownloadInfo>): void | Queries download tasks. This API uses an asynchronous callback to return the **DownloadInfo** object. |
| queryMimeType(): Promise\<string> | Queries the MIME type of this download task. This API uses a promise to return the MIME type. |
| queryMimeType(callback: AsyncCallback\<string>): void | Queries the MIME type of this download task. This API uses an asynchronous callback to return the MIME type. |
| on(type: 'progress', callback:AsyncCallback <uploadedSize:number,totalSize:number> => void): void | Enables listening for upload task progress changes. This API uses an asynchronous callback to return the upload progress. If this API is called multiple times, the callback passed in the last call is used. |
| on(type: 'headerReceive', callback: AsyncCallback\<object> => void): void | Enables listening for the header receive event. This API uses an asynchronous callback to return the HTTP header response. If this API is called multiple times, the callback passed in the last call is used. |
| off(type: 'progress', callback:AsyncCallback<uploadedSize:number,totalSize:number>=> void): void | Disables listening for upload task progress changes. This API uses an asynchronous callback to return the upload progress. |
| off(type: 'headerReceive', callback:AsyncCallback\<object> => void): void | Disables listening for the header receive event. This API uses an asynchronous callback to return the HTTP header response. |
| remove(): Promise\<boolean> | Removes this upload task. This API uses a promise to return the result. |
| remove(callback: AsyncCallback\<boolean>): void | Removes this upload task. This API uses an asynchronous callback to return the result. |
| on(type: 'fail', callback: (err: number, result?: Array) => void): void | Enables listening for the upload failure event. This API uses a callback to return the result. |
| off(type: 'fail', callback?: (err: number, result?: Array) => void): void | Disables listening for the upload failure event. This API uses a callback to return the result. |
| on(type: 'complete', callback: (code: Array, result?: Array) => void): void | Enables listening for the upload completion event. This API uses a callback to return the result. |
| off(type: 'complete', callback?: (code: Array, result?: Array) => void): void | Disables listening for the upload completion event. This API uses a callback to return the result. |
| filename | string | File name in the request header when multiple parts are submitted. |
| name | string | Name of a form item when multiple parts are submitted. The default value is **file**. |
| uri | string | Local path for storing files. Protocol types **dataability** and **internal** are supported. **internal** supports only temporary directories. Example: **dataability:///com.domainname.dataability.persondata/person/10/file.txt internal://cache/path/to/file.txt**. |
| type | string | Type of the file content. By default, the type is obtained based on the extension of the file name or URI. |