Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8237181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:23:18+00:00 2026-06-07T19:23:18+00:00

I know there are a couple questions on SO already concerning this but none

  • 0

I know there are a couple questions on SO already concerning this but none of those solutions worked.

I’m attempting to click a div, which in turn jQuery makes a get request to my contoller and finally downloads the static file (Zip). Using the chrome dev tools, I see the request going and coming back as a valid 200. The response of the request appears to be the chrome’s attempted render but I can make out the names of the files that are contained within the zip file so I can tell it’s finding everything correct.

The response headers are:

Content-Type:application/zip
Content-disposition:attachment;filename=myFile.zip
Date:Thu, 12 Jul 2012 20:18:05 GMT
Server:Apache-Coyote/1.1
Transfer-Encoding:chunked

My controller logic:

    def root = request.getSession().getServletContext().getRealPath("/")

    def file = new File("C:\path\to\my\file")   

    if (file.exists()) { 
        def os = response.outputStream                
        response.setHeader("Content-Type", "application/zip") 
        response.setHeader("Content-disposition", "attachment;filename=${file.name}")

        def bytes = file.text.bytes 
        for(b in bytes) { 
           os.write(b) 
        } 

        os.flush()
                           org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes().renderView = false 
     }

I’m not sure why my browser is not actually downloading the file. I’ve tried so many different variants of the controller logic but all with the same result.

Some things I’ve tried:

  • Content-Type as ‘application/octect-stream;’
  • response.outputStream << file.bytes
  • response.outputStream << file.newInputStream()
  • I’ve added content-length
  • Moving the content type after the stream writes

I’m using Grails 2.0.4

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T19:23:19+00:00Added an answer on June 7, 2026 at 7:23 pm

    Gregg’s comment is correct, but there are workarounds, here is how I have this working:

    Grab the jQuery AJAX file download plugin (hope you are using jquery 😉 )

    I’ve seen an alternative but not tried it

    This does a HTTP request (not Ajax) based on dynamically building a form and posting that to the controller while still giving you the AJAX experience you are after. If this seems a tad clunky, it is, but its the only way I’ve found this to work. The URL above has a dicussion on the potential issues.
    In jQuery call the plugin like:

    $("#myDiv").click(function () {
       $.download('${createLink(controller: 'download', action: 'zipFile')}', 'fileName=' + $("#myTextBox").val()); 
    });
    

    Your controller looks close, using what you have already tried should work:

    response.setHeader("Content-Type", "application/zip") 
    response.setHeader("Content-disposition", "attachment;filename=${file.name}")
    response.outputStream << file.newInputStream()
    

    I’ve been using this for a while now without any issues (yet)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know there were a couple similar questions, but none solved my problem. This
I know there are a couple of questions regarding this Access Error message, but
I know there are a lot of questions around on this subject, but I've
I know this question has been asked a couple of times, but there's something
I know that there are couple of questions here about a countdown timer but
There are a couple of questions similar to this on stack overflow but not
I know there are already a couple of questions out there about sharepoint development
I know there's a lot of questions on SO similar to this, but I
I know there is a lot on this topic but I can't get any
I know there are a lot of similar questions on SF, but I think

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.