Download request
Interface declaration
Import module
Interface definition
request.download(OBJECT)
Download files
Parameters:
| Parameter | Type | Required | Description |
| url | String | Yes | Resource URL |
| header | String | No | Request header. All its properties will be set to the header part of the request. |
| filename | String | No | Download filename. Default is obtained from the network request or URL. |
| success | Function | No | Callback for success |
| fail | Function | No | Callback for failure |
| complete | Function | No | Callback for completion (invoked for both success and failure) |
success return value:
| Parameter | Type | Description |
| token | String | Download token, used to get the download status |
Example:
request.onDownloadComplete(OBJECT)
Listen for download tasks
Parameters:
| Parameter | Type | Required | Description |
| token | String | Yes | Token returned by the download interface |
| success | Function | No | Callback for success |
| fail | Function | No | Callback for failure |
| complete | Function | No | Callback for completion (invoked for both success and failure) |
success return value:
| Parameter | Type | Description |
| uri | String | URI of the downloaded file (by default, this file is in the app's cache directory. If the file type is an image or video and you want users to view it in apps like the gallery, you need to move it to a public directory. You can achieve this using methods from the media interface.) |
fail error codes:
| Error Code | Description |
| 1000 | Download failed |
| 1001 | Download task does not exist |
Example:
Support details
| Device | Description |
| Xiaomi S1 Pro Fitness & Health Watch | Supported |
| Xiaomi Band 8 Pro | Not supported |
| Xiaomi Band 9 / 9 Pro | Not supported |
| Xiaomi Watch S3 | Supported |
| Redmi Watch 4 | Not supported |
| Xiaomi Wrist ECG & Blood Pressure Recorder | Not supported |
| Xiaomi Band 10 | Not supported |
| Xiaomi Watch S4 | Supported |
| REDMI Watch 5 | Supported |