I'm requesting JSP from Javascript (both belong to the same Zimlet)
I need to return some binary file in response to that request. Here is JSP code
I also tried "application/force-download" and "application/octet-stream" as "contentType".
I expect a browser to show "download file" dialog but instead of that file content is printed as text
file_content_toast.jpg
How to fix that?
Code:
var jspUrl = this.getResource("my.jsp");
var callback = new AjxCallback(this, this._rpcCallback, ["param1", "param2"]);
AjxRpc.invoke(null, jspUrl, null, callback, true);
Code:
<%@ page import="java.io.FileInputStream" %>
<%@ page import="java.io.BufferedInputStream" %>
<%@ page import="java.io.File" %>
<%@ page import="java.io.IOException" %>
<%
ServletOutputStream outStream=response.getOutputStream();
File myfile = new File("/tmp/attachment.zip");
response.setContentType("application/x-download");
response.setHeader("Content-Disposition","attachment;filename=attachment.zip");
response.setContentLength( (int) myfile.length( ) );
FileInputStream input = new FileInputStream(myfile);
BufferedInputStream buf = new BufferedInputStream(input);
int readBytes = 0;
while((readBytes = buf.read( )) != -1)
outStream.write(readBytes);
outStream.flush();
outStream.close();
buf.close();
%>
I expect a browser to show "download file" dialog but instead of that file content is printed as text
file_content_toast.jpg
How to fix that?