eligrey / eligrey/FileSaver.js
Can someone show me an reliable solution to download files?
- Dominant language
- JavaScript
- Stars
- 22k
- Forks
- 4.3k
- PR merge metrics
- No merged PRs in 30d
Description
Can someone please show me a reliable alternative (pure code or a framework (please supported)) with which I can download data under React. There a a ton of frameworks, most of them not really supported anymore (e.g. js-file-download)
I'm a little desperate because in 2021 it will still be difficult to reliably download a file in all browsers.
This framework does not work e.g. in the iMac Apple and I think that the owner of this repository no longer has any desire to maintain this framework.
Right now I am doing workaround over workaround to get the file downloaded:
```js
function getPdfFile( response: MyAxiosResponse ): void {
if ( response.data.messages.length === 0 ) {
const binaryString = window.atob( response.data.response.balanceSheetPdf );
const len = binaryString.length;
const bytes = new Uint8Array( len );
for ( let i = 0; i < len; i++ ) {
bytes[i] = binaryString.charCodeAt( i );
}
const file = new Blob( [bytes.buffer], { type: 'application/pdf' } );
const fileURL = URL.createObjectURL( file );
if(isIOS()){
//window.open not working on Apple. Don´t know why. Therefore download the file
FileSaver.saveAs( file, 'BalanceSheet.pdf' );
}else{
window.open( fileURL );
}
}
}
```
I thank you for any reliable solution.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.