Skip to content

Payment-Center-For-Africa/file-downloader

Repository files navigation

file-downloader

File downloader for any web-based project.

NPM JavaScript Style Guide

Install

npm install @payment-center-for-africa/file-downloader@1.0.1

See Example

Usage

downloadFileDisposition

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');
}

downloadFile

This function will donwload the file.

function downloadFile(data: Blob, fileName: string): string;

import { downloadFile } from 'file-downloader';

downloadFile(blob, 'file.pdf');

Built with

  • TypeScript

License

This project is licensed under the MIT License - see the LICENSE.md file for details