Results 1 to 2 of 2

Thread: How to return a file for download by Zimbra Zimlet?

  1. #1
    Join Date
    Apr 2013
    Posts
    33
    Rep Power
    0

    Default How to return a file for download by Zimbra Zimlet?

    I'm requesting JSP from Javascript (both belong to the same Zimlet)

    Code:
    var jspUrl = this.getResource("my.jsp");
    var callback = new AjxCallback(this, this._rpcCallback, ["param1", "param2"]);
    AjxRpc.invoke(null, jspUrl, null, callback, true);
    I need to return some binary file in response to that request. Here is JSP code

    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 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?

  2. #2
    Join Date
    Apr 2013
    Posts
    33
    Rep Power
    0

    Default

    Well, it was found that this is not Zimbra/Zimlet question.
    Code:
    window.open(fileUrl)
    in _rpcCallback function does the trick.

Similar Threads

  1. Unable to return form Briefcase zimbra file download
    By Uula in forum General Questions
    Replies: 0
    Last Post: 08-16-2011, 05:05 AM
  2. Download file attachement from Zimbra take a long time
    By halim.chaibi in forum Administrators
    Replies: 0
    Last Post: 02-28-2011, 02:53 AM
  3. Zimbra Zimlet Taskreminder can not download
    By antond in forum Zimlets
    Replies: 0
    Last Post: 02-15-2010, 08:12 AM
  4. which tar file to download
    By linuxguru in forum Installation
    Replies: 1
    Last Post: 01-08-2010, 12:20 AM
  5. Zimlet Return/Read Receipt
    By hosterix in forum Zimlets
    Replies: 9
    Last Post: 09-04-2009, 08:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •