Files
twenty/front/src/modules/activities/files/utils/downloadFile.ts
T
brendanlaschke 7e454d2013 Attachments (#2716)
* create attachment site

* add deletion

* - fix person create attachment

* - add presentation type
- add some more file endings
- various fixes
2023-11-29 16:58:58 +01:00

19 lines
570 B
TypeScript

export const downloadFile = (fullPath: string, fileName: string) => {
fetch(process.env.REACT_APP_SERVER_BASE_URL + '/files/' + fullPath)
.then((resp) =>
resp.status === 200
? resp.blob()
: Promise.reject('Failed downloading file'),
)
.then((blob) => {
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.style.display = 'none';
a.href = url;
a.download = fileName;
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
});
};