Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ngx-filesaver

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ngx-filesaver

Simple file save with FileSaver.js

  • 0.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
48K
decreased by-7.83%
Maintainers
1
Weekly downloads
 
Created
Source

ngx-filesaver

Simple file save with FileSaver.js

Build Status

示例

demo

安装

npm install file-saver ngx-filesaver --save

添加 FileSaverModule 模块到项目中:

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

使用方法

支持服务 FileSaverService.save() 或属性指令 fileSaver 两种保存方式。

1、FileSaverService

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

onSave() {
  let options = new RequestOptions({
    responseType: ResponseContentType.Blob // 这里必须是Blob类型
  });

  this._http.get('demo.pdf', options).subscribe(res => {
    this._FileSaverService.save((<any>res)._body, fileName);
  });
}

2、fileSaver 属性指令

配置型
<button type="button" 
        fileSaver 
        [fileName]="'中文pdf.pdf'"
        [url]="'assets/files/demo.pdf'"
        [header]="{ token: 'demo' }"
        [query]="{ pi: 1, name: 'demo' }">Download PDF</button>

fileSaver:属性指令名称。

url:下路路径。

fileName:文件名。【选填】

header:请求的 headers 属性值,一般用来指定 token 之类。【选填】

query:额外的查询参数。【选填】

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

Keywords

FAQs

Package last updated on 09 Apr 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc