java - Playframework 2.5.0 : Unable to serve server-side generated zip file -
my playframework 2.5.0 application has serve temporary created zip file. create , fulfill zip file in /tmp directory, without problem (i can open in place , extract contained files).
but file sent client seems truncated , can't opened.
string temppath = "/tmp/" + label + ".zip"; file zipfile = new file(temppath); zipfile.deleteonexit(); zipoutputstream zos = null; try { zos = new zipoutputstream(new bufferedoutputstream(new fileoutputstream(zipfile))); (/* loops through files zip */) { inputstream = methodtogetthedocument(); zipentry zipentry = new zipentry(document.getlabel()); zos.putnextentry(zipentry); byte[] bytes = new byte[2048]; int count = is.read(bytes); while (count > -1) { zos.write(bytes, 0, count); count = is.read(bytes); } is.close(); zos.closeentry(); } return ok(zipfile); } catch (exception e) { return badrequest("bad request"); } { try { zos.close(); } catch (exception e) { e.printstacktrace(); } }
i return classical result object... problem ?
you have "close" zip file using zos.close()
before return ok(zipfile)
Comments
Post a Comment