To prevent direct URL leaks of your storage bucket, stream the file securely through your backend API. javascript
import React, { useState } from 'react'; const DownloadButton = ({ songId }) => { const [loading, setLoading] = useState(false); const handleDownload = async () => { setLoading(true); try { const response = await fetch(`/api/v1/download/${songId}`, { headers: { 'Authorization': `Bearer ${localStorage.getItem('token')}` } }); if (!response.ok) throw new Error('Download failed'); // Convert response to a blob const blob = await response.blob(); const url = window.URL.createObjectURL(blob); // Create temporary link to fire the browser download const a = document.createElement('a'); a.href = url; // Extract filename from headers if sent, or fallback a.download = "Lale_Memmedova_Cicek.mp3"; document.body.appendChild(a); a.click(); // Cleanup a.remove(); window.URL.revokeObjectURL(url); } catch (error) { console.error("Error downloading file:", error); } finally { setLoading(false); } }; return ( ⬇️ {loading ? 'Yüklənir...' : 'Çiçək Yüklə'} ); }; Use code with caution. 🔒 Security & Best Practices
If storing files on cloud storage like AWS S3 or Google Cloud Storage, generate time-sensitive signed URLs rather than routing large files through your API.



