Download Flow

Downloading files from Terabox is a two-step process. First, you obtain a temporary download link (dlink), and then you download the content using that link with specific headers.

1. Get Download Link

Endpoint: GET /rest/2.0/pcs/file

This request asks the server for the location of the file's binary data.

Parameters

Parameter Type Required Description
method string Yes Always download.
app_id string Yes Always 250528.
path string Yes Full path of the file to download.
jsToken string Yes Your session security token.

Code Examples

=== "cURL"

```bash
# Use -I (Head) to just see the headers, as this returns a 302 Redirect
curl -I "https://1024terabox.com/rest/2.0/pcs/file?method=download&app_id=250528&path=/video.mp4&jsToken=TOKEN" \
  -H "Cookie: ndus=YOUR_COOKIE"

# The output will contain:
# HTTP/1.1 302 Found
# Location: https://d10.terabox.com/file/... (This is your dlink)
```

=== "Python"

```python
params = {
    'method': 'download',
    'app_id': '250528',
    'path': '/MyVideo.mp4',
    'jsToken': js_token
}

# requests follows redirects by default. 
# Use stream=True to get the final URL without downloading the body immediately.
resp = session.get('https://1024terabox.com/rest/2.0/pcs/file', params=params, stream=True)

# The final URL is the direct download link (dlink)
download_url = resp.url
print(f"Download URL: {download_url}")
```

=== "Node.js"

```javascript
const resp = await client.get('/rest/2.0/pcs/file', {
    params: {
        method: 'download',
        app_id: '250528',
        path: '/video.mp4',
        jsToken: 'TOKEN'
    },
    maxRedirects: 0, // Prevent auto-redirect to capture the header
    validateStatus: status => status >= 200 && status < 400
});

const downloadUrl = resp.headers.location;
console.log("Direct Link:", downloadUrl);
```

2. Download Content

Once you have the download_url (dlink), you can fetch the file content.

Critical Requirements: * User-Agent: You MUST use the exact same User-Agent string used in Step 1. If they mismatch, the server may reject the request (403 Forbidden). * Cookie: The ndus cookie is required. * Range Header: Highly recommended for large files. It allows you to download in chunks (e.g., "bytes=0-1048575") or resume interrupted downloads.

Code Examples

=== "cURL"

```bash
# Download the file to output.mp4
curl "https://d10.terabox.com/file/..." \
  -H "Cookie: ndus=YOUR_COOKIE" \
  -H "User-Agent: Mozilla/5.0..." \
  -o output.mp4
```

=== "Python"

```python
headers = {
    'User-Agent': 'Mozilla/5.0 ...', # Must match previous request
    'Cookie': 'ndus=...'
}

# Optional: Download first 1MB only
headers['Range'] = 'bytes=0-1048575'

# stream=True is efficient for large files
r = requests.get(download_url, headers=headers, stream=True)

with open('video_part.mp4', 'wb') as f:
    for chunk in r.iter_content(chunk_size=8192):
        f.write(chunk)
```

=== "Node.js"

```javascript
const fs = require('fs');

const response = await axios({
    method: 'get',
    url: downloadUrl,
    responseType: 'stream',
    headers: {
        'User-Agent': 'Mozilla/5.0 ...', // Match exactly
        'Cookie': 'ndus=...'
    }
});

// Pipe the stream to a file
const writer = fs.createWriteStream('video.mp4');
response.data.pipe(writer);

writer.on('finish', () => console.log('Download complete.'));
```