我有一个组件,可以使用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时打开文件