---
name: "downloadFile"
mode: "kit"
versionRequirements:
  - { name: "BaseKit", version: "2.3.2" }
platform:
  - "iOS"
  - "Android"
async: true
title: "ty.downloadFile"
---

## downloadFile

> [VERSION] BaseKit >= 2.3.2

> [PLATFORM] iOS, Android

> ⚡ **Supports Promise** — Returns a Promise when success / fail / complete callbacks are omitted.

### Description

Download a file resource to local storage. The client directly initiates an HTTPS GET request and returns the file's local temporary path (local path). The maximum file size per download is 200 MB. Please read the related notes before use. Note: Specify an appropriate Content-Type header in the server response to ensure the client handles the file type correctly.

### Parameters

| Property | Type | Required | Default | Since | Description |
| --- | --- | --- | --- | --- | --- |
| `url` | `string` | Yes | - | `2.3.2` | URL of the resource to download |
| `header` | `Record<string, string>` | No | - | `2.3.2` | HTTP request headers; Referer cannot be set |
| `timeout` | `number` | No | - | `2.3.2` | Timeout in milliseconds |
| `filePath` | `string` | No | - | `2.3.2` | Path to store the file after download (local path) |
| `complete` | `() => void` | No | - | - | Callback when the API call completes (invoked on both success and failure) |
| `success` | `(params: Object) => void` ↓see below | No | - | - | Callback on successful API call |
| `fail` | `(params: Object) => void` ↓see below | No | - | - | Callback on API call failure |

#### success callback parameters

| Property | Type | Since | Description |
| --- | --- | --- | --- |
| `tempFilePath` | `string` | `3.2.6` | Temporary file path (local path). Returned when no filePath is provided; the downloaded file is stored in a temporary file |
| `filePath` | `string` | `3.2.6` | User file path (local path). Returned when filePath is provided; identical to the provided filePath |
| `statusCode` | `number` | `3.2.6` | HTTP status code returned by the developer server |
| `profile` | `Profile` | `3.2.6` | Debug information during the network request |

#### fail callback parameters

| Property | Type | Description |
| --- | --- | --- |
| `errorMsg` | `string` | Error message |
| `errorCode` | `string \| number` | Error code |
| `innerError` | `Object` | Error extension |

##### fail(params).innerError properties

| Property | Type | Description |
| --- | --- | --- |
| `errorCode` | `string \| number` | Extended error code |
| `errorMsg` | `string` | Extended error info |


### Referenced Types

##### `interface` Profile

| Property | Type | Since | Description |
| --- | --- | --- | --- |
| `redirectStart` | `number` | `3.2.6` | Time of the first HTTP redirect. Only counted for same-domain redirects; otherwise 0 |
| `redirectEnd` | `number` | `3.2.6` | Time when the last HTTP redirect completes. Only counted for same-domain redirects; otherwise 0 |
| `fetchStart` | `number` | `3.2.6` | Time when the component is ready to fetch resources using an HTTP request, which occurs before checking the local cache |
| `domainLookupStart` | `number` | `3.2.6` | DNS lookup start time. If local cache is used (no DNS lookup) or a persistent connection is used, equals fetchStart |
| `domainLookupEnd` | `number` | `3.2.6` | DNS lookup end time. If local cache is used (no DNS lookup) or a persistent connection is used, equals fetchStart |
| `connectStart` | `number` | `3.2.6` | HTTP (TCP) connection start time. If a persistent connection is used, equals fetchStart. Note: If a transport-level error occurs and a new connection is established, this shows the start time of the new connection |
| `connectEnd` | `number` | `3.2.6` | HTTP (TCP) connection established time (handshake complete). If a persistent connection is used, equals fetchStart. Note: If a transport-level error occurs and a new connection is established, this shows the completion time of the new connection. Handshake completion includes secure connection established and SOCKS authorization |
| `SSLconnectionStart` | `number` | `3.2.6` | SSL connection start time; 0 if not a secure connection |
| `SSLconnectionEnd` | `number` | `3.2.6` | SSL connection completion time; 0 if not a secure connection |
| `requestStart` | `number` | `3.2.6` | Time when the HTTP request starts reading the actual document (connection established), including reads from local cache. On connection error and reconnect, this shows the time the new connection was established |
| `requestEnd` | `number` | `3.2.6` | Time when the HTTP request finishes reading the actual document |
| `responseStart` | `number` | `3.2.6` | Time when HTTP starts receiving the response (first byte received), including reads from local cache |
| `responseEnd` | `number` | `3.2.6` | Time when the HTTP response is fully received (last byte received), including reads from local cache |
| `rtt` | `number` | `3.2.6` | Real-time RTT during the connection for this request |
| `estimate_nettype` | `string` | `3.2.6` | Estimated network status: slow 2G/2G/3G/4G |
| `httpRttEstimate` | `number` | `3.2.6` | Protocol layer’s RTT estimate of the current network based on multiple requests (for reference only) |
| `transportRttEstimate` | `number` | `3.2.6` | Transport layer’s RTT estimate of the current network based on multiple requests (for reference only) |
| `downstreamThroughputKbpsEstimate` | `number` | `3.2.6` | Estimated download kbps for the current network |
| `throughputKbps` | `number` | `3.2.6` | Actual download kbps of the current network |
| `peerIP` | `string` | `3.2.6` | IP address of the current request |
| `port` | `number` | `3.2.6` | Port number of the current request |
| `socketReused` | `boolean` | `3.2.6` | Whether the connection is reused |
| `sendBytesCount` | `number` | `3.2.6` | Bytes sent |
| `receivedBytedCount` | `number` | `3.2.6` | Bytes received |


### Examples

```tsx
ty.downloadFile({
  url: "https://airtake-public-data-1254153901.cos.ap-shanghai.myqcloud.com/ttttestfile/test_video.mp4",
  success: data => {
    console.log(data);
  },
  fail: error => {
    console.error(error);
  },
});
```
