Currently, I am utilizing ASP.NET Core and Angular to create a web application. In one of the controller actions, I am returning a File like this:
return Ok(Microsoft.AspNetCore.Mvc.File(await GetFileContents(args), "application/pdf"));
Then in TypeScript, I am reading the contents as shown below:
this.myService.getPDFFile(requestData)
.subscribe(data => this.downloadFile(data))
private downloadFile(data: any) {
const blob = new Blob([data], { type: 'application/pdf' });
saveAs(blob, 'result.pdf');
}
Upon inspecting the data contents, I can see the bytes displayed as follows:
{
"fileContents": "JVBERi0xLjQNCiWio4+TDQo0IDAgb2JqDQo8PC9UaXRsZSA8RkVGRj4gL0F1dGhvciA8RkVGRj4gL1N1YmplY3QgPEZFRkY+IC9LZXl3b3JkcyA8RkVGRj4gL0NyZWF0b3IgPEZFRkY+IC9Qcm9kdWNlciA8RkVGRjAwNDQwMDY1MDA3NjAwNjUwMDZDMDA2RjAwNzAwMDY1MDA3MjAwMjAwMDQ1MDA3ODAwNzAwMDcyMDA2NTAwNzMwMDczMDAyMDAwNDkwMDZFMDA2MzA..",
"contentType": "application/pdf",
"fileDownloadName": "",
"lastModified": null,
"entityTag": null,
"enableRangeProcessing": false
}
However, when attempting to open the saved PDF file, it shows as invalid. What could be the issue here?