So I am calling an API, which returns to my Angular a file, like so:
getFile(fileInformation) {
const req = new HttpRequest('POST', 'filedownload', fileInformation, { reportProgress: true, responseType: "blob" });
return this.http.request(req);
}
And in the API Controller (I followed this SO top answer to figure this step out):
Public Function GetFile(fileInformation As FileDto) As HttpResponseMessage
Dim filePath = Path.Combine(FileConstants.FilePath, fileInformation.FileType, fileInformation.FileName)
Dim fileStream = New FileStream(filePath, FileMode.Open, FileAccess.Read)
Dim result = new HttpResponseMessage(HttpStatusCode.OK)
result.Content = New StreamContent(fileStream)
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream")
Return result
End Function
The returned result from this call is of HttpResponse
, and the body is of type Blob
.
HttpResponse: {
blob: {
size: 289940,
type: "application/octet-stream"
},
headers: ...,
status: 200,
...
}
How do I now trigger a download for this file in the Angular component where I receive the response?