Files
twenty_crm/packages/twenty-front/src/modules/activities/files/utils/downloadFile.ts
Samyak Piya 2b82347fdc Refactor File Download Logic and Streamline Test Suite (#9281)
Closes #9277 

## Summary of Changes
- Updated the file-download functionality to use the `saveAs` method
from the `file-saver` library, ensuring a more reliable and consistent
implementation.
- Removed redundant tests to streamline the test suite and reduce
maintenance overhead.

## Testing Performed
- [x] Verified that exporting the view to a CSV file works as expected.
2024-12-31 14:08:22 +01:00

15 lines
406 B
TypeScript

import { saveAs } from 'file-saver';
import { getFileAbsoluteURI } from '~/utils/file/getFileAbsoluteURI';
export const downloadFile = (fullPath: string, fileName: string) => {
fetch(getFileAbsoluteURI(fullPath))
.then((resp) =>
resp.status === 200
? resp.blob()
: Promise.reject('Failed downloading file'),
)
.then((blob) => {
saveAs(blob, fileName);
});
};