jeudi 26 février 2015

Ember js download from service stack

So I need to find way how to download CSV file from service stack service via ember js app. Unfortunetly I am new in client / server things and file transfering with http.


I have method that creates CSV httpResult 'thing'




public HttpResult Get(ClaimPrintRequest printRequest)
{
string csvBody;
using (var session = NHibernateFactory.OpenSession())
{
var testClaims = session.QueryOver<Claim>().Take(10).List();
var testClaimsMapped = testClaims.Select(Mapper.Map<ClaimGridDto>).ToList();
csvBody = ServiceStack.Text.CsvSerializer.SerializeToCsv(testClaimsMapped);
}
using (var streamOfCsvString = GenerateStreamFromString(csvBody))
{
return new HttpResult(
new MemoryStream(Encoding.UTF8.GetBytes(csvBody)), "application/CSV");
}



}


and i have my action (coffee & javascript):



actions:
printGrid: ->
self = @
claimPrintRequest =
tempVal:'abc'
$.ajax(
url:'/api/print/claim'
type:'GET'
dataType: "json"
data: claimPrintRequest
).then(httpResult) ->
console.log 'abc'

actions: {
printGrid: function() {
var claimPrintRequest, self;
console.log('i am here 1');
self = this;
claimPrintRequest = {
tempVal: 'abc'
};
return $.ajax({
url: '/api/print/claim',
type: 'GET',
dataType: "application/csv",
data: claimPrintRequest
}).then(function(httpResult) {
return console.log('abc');
});
}


} });


and my button:



<button class ="btn btn-primary" {{action 'printGrid' }}>Print</button>


I know i am doing whole process WRONG or maybe part of it, but if i look into network:



Accept:*/*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:pl-PL,pl;q=0.8,en-US;q=0.6,en;q=0.4
Connection:keep-alive
Cookie:ss-pid=PCbUzmx01zh4wo7Wjm9z; ss-id=neElkAxnCOFbSOCG87in
Host:localhost:17951
Referer:http://localhost:17951/App/
User-Agent:Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36
X-Requested-With:XMLHttpRequest
Query String Parametersview sourceview URL encoded
tempVal:abc
Response Headersview source
Accept-Ranges:bytes
Cache-Control:private
Content-Length:7259
Content-Type:application/CSV
Date:Thu, 26 Feb 2015 10:50:15 GMT
Server:Microsoft-IIS/8.0
Vary:Accept
X-AspNet-Version:4.0.30319
X-Powered-By:ASP.NET
X-Powered-By:ServiceStack/4.036 Win32NT/.NET
X-SourceFiles:=?UTF-8?B?QzpcVXNlcnNcQWRtaW5pc3RyYXRvclxEb2N1bWVudHNcd2ViLXFhaXNcV2ViUWFpc1xPQy5XZWJRYWlzLlNlcnZpY2VcYXBpXHByaW50XGNsYWlt?=


it seems there is something


Anyone know or could give me a tip how to do this?





Aucun commentaire:

Enregistrer un commentaire