Download 使用WebAPI核心和Angular 7下载文件

Download 使用WebAPI核心和Angular 7下载文件,download,asp.net-core-webapi,angular7,imagedownload,Download,Asp.net Core Webapi,Angular7,Imagedownload,我试图下载文件图像或PDF的角度,但没有成功。 我确实喜欢下面 <a href="https://localhost:44344/UploadedFiles/IMG_20190314_205925_3be1d2b3-3bac-4184-8468-995d58d5ff80.jpg">Downlod image</a> 服务台 downloadFile(fileName: any) { return this.http.get(this.baseUrl + "Doc

我试图下载文件图像或PDF的角度,但没有成功。 我确实喜欢下面

<a href="https://localhost:44344/UploadedFiles/IMG_20190314_205925_3be1d2b3-3bac-4184-8468-995d58d5ff80.jpg">Downlod image</a>
服务台

downloadFile(fileName: any) {
    return this.http.get(this.baseUrl + "Document/DownloadFile/" + fileName);
  }
当我运行我的应用程序时,点击下载按钮,api函数成功运行,但在angular中,控制台中出现如下错误

问题在哪里?我只是想,文件应该下载按钮点击。
请指导我。

为了达到您的要求,您可以使用我点击的链接,它是在同一选项卡中打开图像,而不是下载。我不知道为什么?@GopalSharma你的请求url是什么?尝试https://localhost:44344/api/Document/UploadedFiles/IMG_20190314_205925_3be1d2b3-3bac-4184-8468-995d58d5ff80.jpg
 <button type="button" (click)="downloadFile(doc.documentName)">Download</button>
 downloadFile(fileName: string) {
    this.documentService.downloadFile(fileName).subscribe((res: any) => {
      console.log(res);
    });
downloadFile(fileName: any) {
    return this.http.get(this.baseUrl + "Document/DownloadFile/" + fileName);
  }
<a href="https://localhost:44344/Document/DownloadFile/file name">Downlod image</a>