I'm tearing my hair out over this issue.
Currently, I have a GET request set up through Angular:
x.DeliverFile = function(fileId) {
$http({
method: "GET",
url: myBase + "Services/DeliverFile?FileID=" + fileId,
headers: myHeaders
}).success(function(data, status, headers, config) {
console.log(data);
});
};
On the WEB API side of things:
If fileinfo.Exists Then
Dim result As New HttpResponseMessage(HttpStatusCode.OK)
With result
.Content = New StreamContent(New FileStream(fileinfo.FullName, FileMode.Open, FileAccess.Read))
.Content.Headers.ContentDisposition = New Headers.ContentDispositionHeaderValue("attachment")
.Content.Headers.ContentDisposition.FileName = fileinfo.Name
.Content.Headers.ContentType = New Headers.MediaTypeHeaderValue("application/octet-stream")
End With
Return result
Else
Return Request.CreateResponse(HttpStatusCode.NotFound)
End If
I've implemented similar functionality using httphandlers multiple times in the past, but seem to be missing something crucial with web api.
While I can see the bytes coming in through console.log(data);
I just can't quite grasp how to prompt the browser to download the file.
I came across this post: Download file from an ASP.NET Web API method using AngularJS
Despite the suggested solution, I'm struggling to fully accept it as the definitive answer, believing there must be a more universally compatible way to trigger downloads across different browsers.