Skip to main content

Streaming Download

Handle large file downloads with streaming. Monitor progress and handle backpressure.

HARD

🔗 Endpoint

GET /api/v1/files/download?format=large&size=5Open in browser ↗

💡 Tips

  • Use streaming to handle large files
  • Monitor Content-Length for progress
  • Handle network interruptions gracefully
  • Consider timeout settings for slow connections

💻 Code Example

// Node.js: Streaming download with progress
const https = require('https');
const fs = require('fs');

const file = fs.createWriteStream('large_file.bin');
let downloaded = 0;

https.get('http://localhost:3003/api/v1/files/download?format=large&size=5', (res) => {
  const totalSize = parseInt(res.headers['content-length']);

  res.on('data', (chunk) => {
    downloaded += chunk.length;
    const progress = ((downloaded / totalSize) * 100).toFixed(1);
    console.log(`Progress: ${progress}%`);
  });

  res.pipe(file);

  file.on('finish', () => {
    file.close();
    console.log('Download complete');
  });
});

🖥️ curl Command

curl -O "https://api.qa-practice.dev/api/v1/files/download?format=large&size=5"