如何使用Angular 7在手机上下载.pdf文件

时间:2019-03-01 02:21:40

标签: angular7 filesaver.js

我有一个组件,可以使用FileSaver

下载pdf文件
export class MyComponent implements OnInit {

  public constructor( private myService: myService ) {}

  ngOnInit(): void {
      this.myService
          .downloadPdf() 
          .subscribe( (file: Blob) => {
               FileSaver.saveAs(file, 'fileName');
          });
  }
}

myService的实现如下:

import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';

@Injectable()
export class MyService {
  constructor(private http: HttpClient) { }

  downloadPdf() {
    const url = `somelinktothe.pdf`;
    return this.http.get(url, { responseType: 'blob' });
  }

}


一切都可以在计算机上正常运行,但在移动设备上实际上可以打开pdf文件而不是保存它。 我在这里想念什么?

更新:下载实际上可在android上正常工作,但在使用Iphone时打开文件

0 个答案:

没有答案