web.xml - Download Excel as xlsx instead of zip format in Scalatra -
i'm writing excel workbook created using apache poi response object directly follows without creating file:
val outputstream: bytearrayoutputstream = new bytearrayoutputstream() workbook.write(outputstream) excelok(response.getoutputstream.write(outputstream.tobytearray))
but once size of response exceeds 8kb, starts getting downloaded zip
file in chrome , octet-stream
in firefox.
my excelok
object looks this:
object excelok { def apply(body: = unit, headers: map[string, string] = excelcontenttype, reason: string = "") = { halt(actionresult(responsestatus(200, reason), body, headers )) } }
and excelcontenttype
(i.e, response headers) below:
val excelcontenttype = map( "access-control-allow-credentials" -> "true", "access-control-allow-methods" -> "get, put, post, delete, options", "access-control-allow-origin" -> "*", "access-control-max-age" -> "1728000", "content-type" -> "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "content-disposition" -> "attachment; filename=excel_report.xlsx" )
i tried adding "transfer-encoding" -> "chunked"
header list doesn't work.
i added snippet in web.xml
file didn't either:
<mime-mapping> <extension>xlsx</extension> <mime-type>application/vnd.openxmlformats-officedocument.spreadsheetml.sheet</mime-type> </mime-mapping>
any regarding useful. note behavior observed after response size exceeds threshold.
you have set response headers before writing content response output stream.
response.setheader("content-type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") response.setheader("content-disposition", "attachment; filename=excel_report.xlsx") workbook.write(response.getoutputstream)
Comments
Post a Comment