Files
twenty/packages/twenty-front/src/modules/activities/files/utils/downloadFile.ts
brendanlaschke c4fecb0a1a Upload image for use in blocknote editor (#3044)
* - upload image to use in blocknote editor
- fix local-storage not in gitignore

* fix lint

* fix runtime config
add tests for body parsing notes and tasks

* lint
2023-12-20 15:16:19 +01:00

21 lines
613 B
TypeScript

import { REACT_APP_SERVER_BASE_URL } from '~/config';
export const downloadFile = (fullPath: string, fileName: string) => {
fetch(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);
});
};