I have different files on my server and I try to download some of them. It has different names and extensions and I can't hardcode them in my code.
How I can download such files?
I'm using .Net core web-api and Angular 7.
.Net:
public async Task<IActionResult> GetFile(DownloadFileQuery query)
{
try
{
var result = await QueryHandler.Handle(query);
return File(result.Content, "application/octet-stream", result.Name);
}
catch (Exception e)
{
return BadRequest(e);
}
}
Angular:
// component
// my console log:
// Blob {size: 103550, type: "application/octet-stream"}
// I don't receive filename and extension
..
downloadFile(fileId: string) {
this.fileService.downloadFile(fileId).subscribe(
data => {
console.log(data);
FileSaver(data, 'How can I find out which file I received?');
},
error => console.log(error)
);
}
..
// service
..
downloadFile(fileId: string) {
const queryParams = new HttpParams()
.set('FileId', param);
return this.http.get(`api/file/file`, { params: queryParams , responseType: 'blob'});
}
..
I expect to get filename.extension in response. Or another way to do this.