Open Closed

Issue download a PDF file in Angular app #1889


User avatar
0
creosource created
  • ABP Framework version: v4.4.0
  • UI type: Angular
  • DB provider: EF Core /
  • Tiered (MVC) or Identity Server Separated (Angular): no
  • Exception message and stack trace:
  • Steps to reproduce the issue:"

I am trying to download a PDF file in Angular from a call to the backend, I have tried a bunch of different methods but get the same results: "Http failure during parsing for https://localhost:44367/downloadreport/f6f8401a-26d6-0ed6-30f8-39fef69a5343" Unexpected token % in JSON at position 0 text: 772 kb

On my backend I have tried creating a controller that return RemoteStreamContent like this:

      [HttpGet]
      [Route("downloadreport/{userTestId}")]
      public async Task<RemoteStreamContent> DownloadReportAsync(Guid userTestId)
      {
         var fileDto = await _reportService.GetPDFReport(userTestId);

         MemoryStream stream = new MemoryStream(fileDto.Content);

         return new RemoteStreamContent(stream, fileDto.Name);
      }
      
I have also tried returning a File() like this:
  [HttpGet]
  [Route("downloadreport/{userTestId}")]
  public async Task<IActionResult> DownloadReportAsync(Guid userTestId)
  {
     var fileDto = await _reportService.GetPDFReport(userTestId);

     return File(fileDto.Content, "application/octet-stream", fileDto.Name);
  }

In Angular I have the following code: downloadUserTest(id: string) { this.reportService.downloadReport(id).subscribe(x => { console.log(x); }); }

Am trying to figure out what I am doing wrong, can someone help please ?

Thanks!


2 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    The servce proxy does not support Download file yet,

    You can try this:

    window.open(
      `${this.apiUrl}/downloadreport/{userTestId}`,
      '_self'
    );;
    
  • User Avatar
    0
    creosource created

    Thanks this worked!

Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11