Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kennethjiang/js-file-download
https://github.com/kennethjiang/js-file-download
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/kennethjiang/js-file-download
- Owner: kennethjiang
- License: mit
- Created: 2016-04-27T15:24:39.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2022-07-30T09:51:39.000Z (over 2 years ago)
- Last Synced: 2024-05-15T21:44:16.815Z (7 months ago)
- Language: JavaScript
- Size: 43 KB
- Stars: 909
- Watchers: 13
- Forks: 120
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome - js-file-download - (JavaScript)
README
# Javascript File Download
Javascript function to trigger browser to save data to file as if it was downloaded.
# Installation
npm install js-file-download --save
# Usage
```javascript
var fileDownload = require('js-file-download');
fileDownload(data, 'filename.csv');
```
## Binary downloadsWhen downloading binary data, the data must be a [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob), otherwise the downloaded file will be corrupted. For example, using [Axios](https://github.com/axios/axios):
```javascript
import Axios from axios;
import fileDownload from 'js-file-download';function download(url: string, filename: string) {
Axios.get(url, {
responseType: 'blob',
}).then(res => {
fileDownload(res.data, filename);
});
}
```