Do" /> Do" /> Do"/>

Downloaded file in Angular Application saved as Unconfirmed XXXXX.crdownload

173 Views Asked by At

Angular 17 application. Trying to download file from database via ASP.NET Web API. Web API code:

[HttpGet("{id}")]
public async Task<IActionResult> DownloadFileFromDatabase(int id)
{
    try
    {
        File2Download f = new File2Download();
        // grab file data from database here
        //
        MemoryStream stream = new MemoryStream(f.FileData);
        return File(stream, f.ContentType, f.FileName);
    } catch(Exception ex)
    {
        return StatusCode(500, ex.Message);
    }
}

Angular code

public downloadFile(id: string, fileName: string){
    console.log(fileName); // this chows correct file name
    let url = this.APIUrl + 'FileManager/'+ id;
    this.http
    .get(url, {
      responseType: 'blob'
    })
    .subscribe((response)=>
    {
      saveAs(response, fileName);
    });
  }

Everything works smooth in local environment, once deployed on the dev server downloaded file comes in as Unconfirmed XXXXX.crdownload, the thing is, the data is not corrupted, when renamed to the correct file name and right extension I'm able to open it up, no problem. Tried my own code on the Angular side, then switched to file saver package, no joy. Please, anybody, any idea?

I have to mention that I tried it in Edge, and it works fine. I feels like the problem is only with Chrome browser.

0

There are 0 best solutions below