feat: download

- able to download file from express
This commit is contained in:
cv
2021-05-26 23:10:00 +02:00
parent 250946fdc6
commit b61a82627e
6 changed files with 63 additions and 0 deletions
+15
View File
@@ -1,6 +1,21 @@
import axios from 'axios';
import { eventsURL } from '../api/apiConstants';
export const downloadEvents = async () => {
await axios({
url: eventsURL + '/download',
method: 'GET',
responseType: 'blob', // important
}).then((response) => {
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'events.json');
document.body.appendChild(link);
link.click();
});
};
export const fetchAllEvents = async () => {
const res = await axios.get(eventsURL);
return res.data;