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

  • Home
  • SEARCH
  • 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 6175509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:56:13+00:00 2026-05-23T23:56:13+00:00

in my grails application using jasper Reports i am creating report in pdf format,

  • 0

in my grails application using jasper Reports i am creating report in pdf format, i want to make it available it for downloading.. so in which directory of my application i need to save file…?
thanks in advance

  • 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-05-23T23:56:14+00:00Added an answer on May 23, 2026 at 11:56 pm

    Possible duplicate?

    You can store the files any where you like but, be aware of the directory your storing the files in so they don’t end up taking up all the disk space if you not actively cleaning them up.

    so, here is what i would do if you want to store the files and allow the user to download them now or later (not tested and it could be better but shows the concept)…

    create a class that represents your directory of reports

    class ReportDirectory{
    
       static final String path = "./path/to/reports/"; //<-- generic path on your SERVER!
    
       static{
           //static initializer to make sure directory gets created.  Better ways to do this but this will work!
    
           File pathAsFile = new File(path).mkdirs()
    
           if (pathAsFile.exists()){
              println("CREATED REPORT DIRECTORY @ ${pathAsFile.absolutePath}");
           }else{
              println("FAILED TO CREATE REPORT DIRECTORY @ ${pathAsFile.absolutePath}");
           }
    
       }
    
       public static File[] listFiles(){
           return new File(path).listFiles(); //<-- maybe use filters to just pull pdfs?
       }
    
       public static void addFile(File file){
           FilesUtil.copyFileToDirectory(file, new File(path)); //<-- using apache-commons-io
       }
    
       public static void deleteAll(){
           listFiles().each(){ fileToDelete ->
               fileToDelete.delete();
           }
       }
    
       public static File findFile(String name){
           listFiles().each(){ fileToCheck ->
    
               if (fileToCheck.name.equals(name)){
                   return fileToCheck
               }
           }
           return null
       }
    
    }
    

    Then in your controller you could do things like this….

    class ReportController{
    
       def runReport = {
           File report = createReport() //<-- your method to create a report.
           ReportDirectory.addFile(report);
    
           redirect(action:"downloadFle" params:[fileName:report.name])
    
       }    
    
    
       def showAllFiles = {
           [files:ReportDirectory.listFiles()]
       }
    
       def downloadFile = {
          def fileName = params.fileName;
    
          def fileToDownload = ReportDirectory.findFile(fileName);
    
          if (fileToDownload){
    
          response.setContentType("application/octet-stream")
          response.setHeader("Content-disposition", "attachment;filename=${fileToDownload .getName()}")
          response.outputStream << fileToDownload.newInputStream()  //<-- ask the user to download
         }else{
             //handle when the file is not found
         }
    
       }
    
       def deleteAllFiles ={
           ReportDirectory.deleteAllFiles()
    
           [files:ReportDirectory.listFiles()] //<-- return the remaining files, if any.
       }
    
    
    }
    

    A few comments about this solution…

    -this doesn’t address MIME types so the browser won’t be able to figure out what kind of binary data is coming over the wire.

    is this helpful?

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

Sidebar

Related Questions

I'm using the Grails Jasper report plugin in my application. Im trying to bind
I am creating an application using Grails Framework for which I plan to use
I am working on a web application (using Grails) which will generate a gift
I want to create web application using Grails. The main layout consists of few
I've got an application that was using Grails 1.3.7 which I've just migrated to
I'm developing a Grails (Version 1.3.3) Web-Application using the Grails Spring-Security Plugin, Spring-Security-Core-1.0.1 (which,
I'm sending multipart mails with attachment from my grails application using the mail plugin
I am using a grails application as backend for a Flex frontend. To be
In my grails application I want to read some values from properties file and
I'm having trouble using Spring Security successfully in my Grails application. I installed the

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.