File downloader for any web-based project.
npm install @payment-center-for-africa/file-downloader@1.0.1
This function will donwload the file using the disposition header to get the file name and extension.
function downloadFileDisposition(data: Blob, disposition: string, fallbackFileName: string): string;
import downloadFileDisposition from 'file-downloader';
const disposition = response.request.getResponseHeader('Content-Disposition');
if (disposition) {
downloadFileDisposition(response.data, disposition, 'file.pdf');
} else {
throw new Error('Content-Disposition header is missing');
}
This function will donwload the file.
function downloadFile(data: Blob, fileName: string): string;
import { downloadFile } from 'file-downloader';
downloadFile(blob, 'file.pdf');
- TypeScript
This project is licensed under the MIT License - see the LICENSE.md file for details