-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDownloadButton.jsx
More file actions
30 lines (26 loc) · 900 Bytes
/
DownloadButton.jsx
File metadata and controls
30 lines (26 loc) · 900 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import React from 'react';
import axios from 'axios';
export default function DownloadButton() {
const downloadZip = async () => {
try {
const response = await axios.get('http://localhost:5000/api/download', {
responseType: 'blob'
});
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'tracks.zip');
document.body.appendChild(link);
link.click();
link.remove();
} catch (error) {
console.error('Download failed:', error);
alert("Download failed: Could not retrieve the ZIP file.");
}
};
return (
<button onClick={downloadZip} style={{ padding: '10px 20px', margin: '20px 0', background: '#007bff', color: 'white', border: 'none', borderRadius: '4px' }}>
Download ZIP
</button>
);
}