Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bbonkr/bbon-filedownload
File download helper
https://github.com/bbonkr/bbon-filedownload
npm
Last synced: 25 days ago
JSON representation
File download helper
- Host: GitHub
- URL: https://github.com/bbonkr/bbon-filedownload
- Owner: bbonkr
- Created: 2020-09-07T04:54:14.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2021-09-11T05:22:09.000Z (about 3 years ago)
- Last Synced: 2024-10-01T23:05:15.195Z (about 1 month ago)
- Topics: npm
- Language: TypeScript
- Homepage: http://bbon.me/bbon-filedownload/
- Size: 706 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# @bbon/Filedownload
[![](https://shields.io/npm/v/@bbon/filedownload)](https://www.npmjs.com/package/@bbon/filedownload) [![](https://shields.io/npm/dt/@bbon/filedownload)](https://www.npmjs.com/package/@bbon/filedownload) [![Build and tag](https://github.com/bbonkr/bbon-filedownload/actions/workflows/build-and-tag.yml/badge.svg)](https://github.com/bbonkr/bbon-filedownload/actions/workflows/build-and-tag.yml) [![publish NPM](https://github.com/bbonkr/bbon-filedownload/actions/workflows/publish-npm.yml/badge.svg)](https://github.com/bbonkr/bbon-filedownload/actions/workflows/publish-npm.yml)
파일 다운로드 코드 조각입니다.
## 설치 Installation
```bash
$ npm install @bbon/filedownload
``````bash
$ yarn add @bbon/filedownload
```## 사용 Usage
[`Axios` 패키지](https://www.npmjs.com/package/axios)를 사용하는 경우 예제 코드 조각입니다.
> responseType 을 'blob' 으로 설정해야 합니다.
```typescript
import Axios from 'axios'
import FileDownloadHelper from '@bbon/filedownload'const requestConfig: AxiosRequestConfig = {
...Axios.defaults,
responseType: 'blob',
};Axios.get(fileDownloadUrl, requestConfig)
.then((res) => {
if (res) {
const contentType =
res.headers['content-type'] || 'application/octet-stream';
const helper = new FileDownloadHelper();
helper.download({
data: res.data,
filename: fileName,
contentType,
});
}
})
.catch((err) => {
console.error(err);
})
.finally(() => {
setLoading(false);
});
```사용예는 [example](https://github.com/bbonkr/bbon-filedownload/example)에서 확인하실 수 있습니다.