I found this question since I too 1) wanted to download a file from the server, 2) the file is in memory on the server and 3) I'm using breeze. And, I agree with Mr. Schmitt that breeze cannot do it. It seems to only be able to return a list of objects (records) -- which makes sense for breeze ... being for data access.
And, like me, I think you want to know how to download a file with or without breeze. I'm not familiar with web communication other than via breeze. I wanted to know how to download a file to a client that so far accesses data via breeze and from a server that so far only accepts queries from breeze. I didn't know whether the client and server were locked into breeze access. Since the answer seems to be that it's not, I feel rather naive.
The answer to how you download a file for a breeze client/server is: don't use breeze! Use some mechanism outside of the breeze ecosystem. I suppose to a seasoned web developer that is probably obvious, but it's not to me who has managed to remain rather ignorant of web technologies for the first 25 years of my career.
I don't know whether this answers your question. At least this might be useful to others who come across this question.
As for how you download a file, I'm guessing there are zillions of SO questions, blog posts and articles about that. But, I'll share my solution that I came up with ... FWIW.
Server code:
[HttpPost]
public HttpResponseMessage RelatedRegistrationsFromRegistration()
{
var httpContent = new ByteArrayContent(...);
httpContent.Headers.ContentType = new MediaTypeHeaderValue("Application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
httpContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = "Related Registrations.xlsx"
};
return new HttpResponseMessage(HttpStatusCode.OK) { Content = httpContent };
}
Client code using angular's $http communcation service:
this.downloadFromUrl = function (url, refs) {
$http({
method: 'POST',
url: url,
data: serializeData({ 'refs': refs }),
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
},
responseType: 'arraybuffer'
}).success(function (data, status, headers) {
var filename = headers('content-disposition').split('=')[1].replace(';', '');
var blob = new Blob([data], { type: headers('content-type') });
if (navigator.msSaveBlob) {
navigator.msSaveBlob(blob, filename);
} else {
var link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.setAttribute('download', filename);
link.click();
link.remove();
}
}).error(function () {
alert('Error');
});
}