Skip to main content

Downloads

Utility to download files from services

Version

Install

NPM

npm install @availity/dl-axios axios

Yarn

yarn add @availity/dl-axios axios

Usage

import AvDownloadApi from '@availity/dl-axios';

const downloadApi = new AvDownloadApi({
clientId: '1234',
});

const download = async () => {
const response = await downloadApi.getAttachment({
params: { id: 'attachment-id' },
});
downloadApi.downloadAttachment(response.data, 'filename.csv', 'text/csv');
};

Note: clientId is required. It is sent as the X-Client-ID header on all requests.

Methods

This class has the following methods to use.

getAttachment(config)

Fetches the attachment from the server. The response type is automatically set to 'blob'. Pass query parameters or headers via the config object.

downloadAttachment(data, filename, mime)

Triggers a file download in the browser.

  • data - Blob data from getAttachment response
  • filename - The filename for the downloaded file
  • mime - (optional) MIME type of the file (e.g., 'text/csv', 'application/pdf')