const downloadFile = async () => { if (downloadId) { try { const response = await axios.get(`http://localhost:5000/download/${downloadId}`, { responseType: 'blob' }); const url = window.URL.createObjectURL(new Blob([response.data])); setFileLink(url); } catch (error) { console.error(error); } } };

if __name__ == '__main__': app.run(debug=True) import React, { useState } from 'react'; import axios from 'axios';

app = Flask(__name__)

const initiateDownload = async () => { try { const response = await axios.post('http://localhost:5000/download'); if (response.data.download_id) { setDownloadId(response.data.download_id); } } catch (error) { console.error(error); } };

# Mock database for demonstration downloads = {}

# Endpoint to stream the file @app.route('/download/<download_id>') def download_file(download_id): if download_id in downloads: file_path = downloads[download_id] return send_file(file_path, as_attachment=True) else: return jsonify({"message": "Invalid download ID"}), 401