Hi Vinod, Since you are using Jaggery, you can use JavaScript to create and download a file. You can have a look on [1], but not sure whether it aligns with your requirement.
[1] - http://blog.eliacontini.info/post/79860720828/export-to-csv-using-javascript-and-the-download Thanks, Inshaf On Thu, Jul 9, 2015 at 1:49 PM, Vinod Kavinda <vi...@wso2.com> wrote: > Hi all, > > I'm trying to download a file from a given URL (File get downloaded if we > directly go to the link via browser), in a jaggery app. > > I need to get the file to the Jaggery backend and send it to the browser > so that file should get downloaded. I tried this by sending a get request > to the relevant URL, setting all the headers received from get response to > the jaggery response and printing the payload as shown below. > > var httpClient = new XMLHttpRequest(); > httpClient.open('GET', url, true); > httpClient.setRequestHeader('COOKIE', session.get('MGT_SESSION')); > > //copy header details > var contentType = > httpClient.getResponseHeader("Content-Type"); > var transferEncoding = > httpClient.getResponseHeader("Transfer-Encoding"); > var vary = httpClient.getResponseHeader("Vary"); > var date = httpClient.getResponseHeader("Date"); > var server = httpClient.getResponseHeader("Server"); > var contentDisposition = > httpClient.getResponseHeader("Content-Disposition"); > > response.addHeader('Content-Type', contentType); > response.addHeader('Transfer-Encoding', transferEncoding); > response.addHeader('Vary', vary); > response.addHeader('Date', date); > response.addHeader('Server', server); > response.addHeader('Content-Disposition', contentDisposition); > > print(httpClient.responseText); > > A file get downloaded as expected. But is is a corrupted file with less > size than actual size of the file. > > I think the reason for this is the data is coming as chunked data packets. > The 'Transfer-Encoding' header value is 'chunked'. > > Any hint on resolving this is much appreciated. > > Thank You, > Vinod > > > -- > Vinod Kavinda > Software Engineer > *WSO2 Inc. - lean . enterprise . middleware <http://www.wso2.com>.* > Mobile : +94 (0) 712 415544 > Blog : http://soatechflicks.blogspot.com/ > > > _______________________________________________ > Dev mailing list > Dev@wso2.org > http://wso2.org/cgi-bin/mailman/listinfo/dev > > -- Inshaf Mahath
_______________________________________________ Dev mailing list Dev@wso2.org http://wso2.org/cgi-bin/mailman/listinfo/dev