All Projects → cipchk → ngx-filesaver

cipchk / ngx-filesaver

Licence: MIT license
Simple file save with FileSaver.js

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to ngx-filesaver

ng2-go-top-button
A simple customizable go-top-button component for Angular projects.
Stars: ✭ 18 (-76.92%)
Mutual labels:  angular-component
Tagify
🔖 lightweight, efficient Tags input component in Vanilla JS / React / Angular / Vue
Stars: ✭ 2,305 (+2855.13%)
Mutual labels:  angular-component
Popover
Popover component for Angular
Stars: ✭ 187 (+139.74%)
Mutual labels:  angular-component
Ng Snotify
Angular 2+ Notification Center
Stars: ✭ 304 (+289.74%)
Mutual labels:  angular-component
Ui Predicate
Finally a Predicate/Rule Editor UI component for the Web 🚀
Stars: ✭ 86 (+10.26%)
Mutual labels:  angular-component
Angular Fullpage
Official Angular wrapper for fullPage.js https://alvarotrigo.com/angular-fullpage/
Stars: ✭ 131 (+67.95%)
Mutual labels:  angular-component
angular-croppie
Angular 1.5+ Component for Croppie
Stars: ✭ 16 (-79.49%)
Mutual labels:  angular-component
Streamsaver.js
StreamSaver writes stream to the filesystem directly asynchronous
Stars: ✭ 2,784 (+3469.23%)
Mutual labels:  filesaver
Angular Cropperjs
CropperJS integration for Angular +6
Stars: ✭ 88 (+12.82%)
Mutual labels:  angular-component
Angular Notifier
A well designed, fully animated, highly customizable, and easy-to-use notification library for your Angular application.
Stars: ✭ 175 (+124.36%)
Mutual labels:  angular-component
Awesome Angular Components
Catalog of Angular 2+ Components & Libraries
Stars: ✭ 3,185 (+3983.33%)
Mutual labels:  angular-component
Ngautocomplete
Light-weight autocomplete component for Angular.
Stars: ✭ 52 (-33.33%)
Mutual labels:  angular-component
Od Virtualscroll
🚀 Observable-based virtual scroll implementation in Angular
Stars: ✭ 133 (+70.51%)
Mutual labels:  angular-component
Ng2 Bs3 Modal
Angular Bootstrap 3 Modal Component
Stars: ✭ 273 (+250%)
Mutual labels:  angular-component
Ngx Avatar
Universal avatar component for angular 2+ applications makes it possible to fetch / generate avatar from different sources
Stars: ✭ 210 (+169.23%)
Mutual labels:  angular-component
awesome-angular
💖 A list of awesome Angular (2️⃣➕) resources
Stars: ✭ 61 (-21.79%)
Mutual labels:  angular-component
Ngx Content Loading
Angular component to create SVG loading placeholders
Stars: ✭ 124 (+58.97%)
Mutual labels:  angular-component
angular-tag-cloud-module
This angular module contains a component which generates tag clouds.
Stars: ✭ 38 (-51.28%)
Mutual labels:  angular-component
MTG-Card-Reader-Web
MTG-Card-Reader 2.0, built as a webpage.
Stars: ✭ 21 (-73.08%)
Mutual labels:  filesaver
Ngx Ueditor
Angular for Baidu UEditor
Stars: ✭ 169 (+116.67%)
Mutual labels:  angular-component

ngx-filesaver

Simple file save with FileSaver.js

NPM version Ci

中文版

Examples

Installation

npm install file-saver ngx-filesaver --save

Add the FileSaverModule module to your project:

import { FileSaverModule } from 'ngx-filesaver';
@NgModule({
  imports: [ FileSaverModule ]
})

Instructions

There are two ways to save a file: using FileSaverService.save() or using the fileSaver directive.

1、FileSaverService

constructor(private _http: Http, private _FileSaverService: FileSaverService) {
}

onSave() {
  this._http.get('demo.pdf', {
    responseType: ResponseContentType.Blob // This must be a Blob type
  }).subscribe(res => {
    this._FileSaverService.save((<any>res)._body, fileName);
  });
}

2、fileSaver directive

Configuration example

<button type="button"
        fileSaver
        [method]="'GET'"
        [fileName]="'中文pdf.pdf'"
        [url]="'assets/files/demo.pdf'"
        [header]="{ token: 'demo' }"
        [query]="{ pi: 1, name: 'demo' }"
        (success)="onSuc($event)"
        (error)="onErr($event)">Download PDF</button>

fileSaver: the directive name Parameters

Parameter Description Type Default
method Request method type string GET
url Request URL string -
fileName Filename when downloading string -
query Additional query parameters. Equivalent to params value string -
header Header configuration. Usually used for especifying access tokens any -
fsOptions FileSaver.js config, can be set autoBom value FileSaverOptions -
success Download success callback EventEmitter<HttpResponse<Blob>> -
error Download error callback EventEmitter<any> -

Custom HTTP type

<button type="button"
        fileSaver
        [http]="onRemote('pdf', true)">Download PDF</button>
onRemote(type: string, fromRemote: boolean): Observable<Response> {
  return this._http.get(`assets/files/demo.${type}`, {
    responseType: ResponseContentType.Blob
  }).map(response => {
    response.headers.set('filename', `demo.${type}`)
    return response;
  });
}

About filenames

The name for the downloaded file is obtained with the following priority:

  1. fileName
  2. response.headers.get('filename')
  3. response.headers.get('x-filename')。

If you are requesting a CORS address, you need to pay attention to the request headers. Setting Access-Control-Allow-Headers: filename should be sufficient

Class Name

Class Name Description
filesaver__not-support Not Supported Browsers
filesaver__disabled During http request

Configuring CommonJS dependencies

WARNING in node_modules/ngx-filesaver/ivy_ngcc/fesm2015/ngx-filesaver.js depends on file-saver. CommonJS or AMD dependencies can cause optimization bailouts.

We cannot change this, the only way is to ignore it:

"build": {
  "builder": "@angular-devkit/build-angular:browser",
  "options": {
     "allowedCommonJsDependencies": [
        "file-saver"
     ]
     ...
   }
   ...
},
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].