Question

Play version 2.2.2.

I have an Enumerator ready to be chunked to the browser and am trying to stream this result

My code is :

val e = getResponseEnumerator()
Ok.chunked(e).as("text/csv").withHeaders(CONTENT_DISPOSITION -> "attachment; filename=testing.csv")


Chrome Browser (ver: 32.0.1700.107) only => I expect a CSV file streamed as a download but I see a text result of comma separated values in my window instead. Not sure where I'm going wrong here. I referenced the documentation regarding "Chunked Responses" from here : http://www.playframework.com/documentation/2.2.x/ScalaStream

My response header is :

HTTP/1.1 200 OK
Content-Type: text/csv
Transfer-Encoding: chunked
Content-Disposition: attachment; filename=testing.csv
...


Firefox (ver: 27.0.1) downloads the file as expected.

Was it helpful?

Solution

Resolved the problem myself.

The problem was I was submitting my request as AJAX from the client. Hence the response sent back to the browser was simply being spat back out into the window. GIGO I believe is Chrome's approach instead of reading the Content-Type header. (possible bug?)

I modified my jquery select to use the :not() selector and exclude the "Generate CSV" button which sends the request to the server synchronously. This fixes the problem on Chrome.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top