Results 1 to 5 of 5

Thread: How to implement download (save as) dialog for TGZ files?

  1. #1
    Join Date
    Aug 2010
    Posts
    9

    Default How to implement download (save as) dialog for TGZ files?

    Hello,

    I am using Spring version 3.0.3.RELEASE. Used Java version is 1.6.

    I m trying to implement Save As dialog that will store some TGZ file. When I try to download some other kind of file (for example some ZIP archive) it works fine.

    This is the used Java code:

    @RequestMapping(method = RequestMethod.POST)
    public ModelAndView submitBackupDatabase(HttpServletRequest request, HttpServletResponse response) {
    response.setContentType("application/x-compressed"); // I try with application/octet-stream and application/x-gzip also.
    response.setHeader("Content-Disposition", "attachment; filename=\"test.tgz\"");

    FileInputStream fis = null;
    try {
    File file = new File("D:/test.tgz");
    byte[] bytes = new byte[(int) file.length()];

    fis = new FileInputStream(file);
    fis.read(bytes);

    response.setContentLength(bytes.length);
    response.getOutputStream().write(bytes, 0, bytes.length);
    response.getOutputStream().flush();
    response.getOutputStream().close();
    } catch (Exception e) {
    log.error(e.getMessage(), e);
    } finally {
    try {
    fis.close();
    } catch (Exception e) {
    log.error(e.getMessage(), e);
    }
    }

    return null;
    }

    Strange thing is when I try to use some other file type it works fine and there is no any error in application logs.

    Could anybody please give some advice about this?
    Maybe, some example of how I should implement this…

    Thanks in advance,
    Ivan

  2. #2
    Join Date
    Oct 2005
    Location
    Mobile, AL
    Posts
    345

    Default

    sounds like a mime type issue with your web server.

    try adding the following to your web server's mime type settings:

    <mime-mapping>
    <extension>tgz</extension>
    <mime-type>application/octet-stream</mime-type>
    </mime-mapping>

  3. #3
    Join Date
    Aug 2010
    Posts
    9

    Default

    Hello MartyJones,

    Thanks for the help, but I have same behavior as earlier.

    I have Tomcat server running on Windows 7, and this is happen when I try to save TGZ file from browser that is running on same machine.

    I try to access this page by using Firefox that is installed on my CentOS 5 virtual machine and it works fine. But it still not working when I access this page from any browser that is running on Windows operating system (I try with Firefox 3.6 and Internet Explorer 8).

    Is there a possibility this is caused because I try to do this on Windows? Is there some work around for this?

    Thanks in advance.
    Best Regards,
    Ivan

  4. #4
    Join Date
    Aug 2010
    Posts
    9

    Default

    Problem solved. It seems to browsers have a problem with TGZ files. I try to do this by using TAR.GZ archive file and it works fine.

    Again, thanks for the help.

    Best regards,
    Ivan

  5. #5
    Join Date
    Mar 2011
    Location
    Washington, DC
    Posts
    60

    Default

    Hi, piffta.


    I have a problem to render pdf in IE. It seemed that my logic almost the same as yours, except content type (application/pdf). Here is a link of my original post http://forum.springsource.org/showth...er-Pdf-in-IE-7
    If possible, can you post your configuration to see whether I did somewrong? Thanks a lot

Tags for this Thread

Posting Permissions

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