I want to create a new directory to store all pdf reports generated by jasper reports and they should be accessible to users to download as well
For example: I am exporting the a file called "pdfreport20110804788.pdf".when i put this file in that directory .i set certain things in controller method and i need the file created to be returned from the groovy method where the new directory is created and its is exported as pdf file so that file should be returned to the controller calling method for further operations
response.setContentType("application/octet-stream")
response.setHeader("Content-disposition", "attachment;filename=${file.getName()}")
response.outputStream << file.newInputStream()
So ,i have been trying these thing by creating the file using the createTempFile method and returning the file to the controller but the file was getting downloaded to c:\ ... location without asking to download or open .can any one please give me the solution for this
There are two things you need to be aware of:
1.) Files generated on the server's disk cannot be directly accessed by a user on your web site. You have to deliver the files through the browser via an output stream.
2.) You cannot freely access the disk of a user on your web site. So, if your web site creates a file on "c:\website\file.pdf" it will always go to the server's "c:" drive and never to the end users "c:" drive. Remember the "c:\" drive is mostly a Windows thing so Unix or mobile users would NOT be able to use the site even if you could do this because they don't have a "c:" drive.
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
Then in your controller you could do things like this....
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?