Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
ngx-filesaver
Advanced tools
Simple file save with FileSaver.js
npm install file-saver ngx-filesaver --save
添加 FileSaverModule
模块到项目中:
import { FileSaverModule } from 'ngx-filesaver';
@NgModule({
imports: [ FileSaverModule ]
})
支持服务 FileSaverService.save()
或属性指令 fileSaver
两种保存方式。
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);
});
}
<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:额外的查询参数。【选填】
<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;
});
}
文件名的获取按以下优先级:fileName =》 response.headers.get('filename') =》 response.headers.get('x-filename')。
如果你请求的是一个CORS跨域地址,需要注意设置 Access-Control-Allow-Headers: filename
,以免无法获取。
FAQs
Simple file save with FileSaver.js
The npm package ngx-filesaver receives a total of 46,734 weekly downloads. As such, ngx-filesaver popularity was classified as popular.
We found that ngx-filesaver demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.