FireGlow
27 May 2009, 6:13 AM
Hey guys!
After it worked out to upload a file, I need to download it again!
The problem is there is no "real" file on the server (I delete it after storing some data in the database), I need to build it out of data from my database.
Now I want to click on a button and start the download dialog isntantly!
I tried to change the outputstream, and I got the the content of the file, but only as a kind of "error" :>
HttpServletResponse response = this.getThreadLocalResponse();
response.setContentType("application/pdf");
response.setHeader("Content-Disposition", "attachment;filename=\"" + "test.pdf\"");
File test = new File("D:/autoexec.cfg");
FileInputStream fis = null;
OutputStream os = null;
int read = 0;
byte[] bytes = new byte[1024];
// First we load the file in our InputStream
fis = new FileInputStream(test);
os = response.getOutputStream();
// While there are still bytes in the file, read them and write them
// to our OutputStream
while ((read = fis.read(bytes)) != -1) {
os.write(bytes, 0, read);
}
I read about a solution to add a hidden panel and redirect it to an existing file. But I don't want to create the file on the server, I just want to have the file in a stream.
Is that possible? If yes how?
thanks for helping
After it worked out to upload a file, I need to download it again!
The problem is there is no "real" file on the server (I delete it after storing some data in the database), I need to build it out of data from my database.
Now I want to click on a button and start the download dialog isntantly!
I tried to change the outputstream, and I got the the content of the file, but only as a kind of "error" :>
HttpServletResponse response = this.getThreadLocalResponse();
response.setContentType("application/pdf");
response.setHeader("Content-Disposition", "attachment;filename=\"" + "test.pdf\"");
File test = new File("D:/autoexec.cfg");
FileInputStream fis = null;
OutputStream os = null;
int read = 0;
byte[] bytes = new byte[1024];
// First we load the file in our InputStream
fis = new FileInputStream(test);
os = response.getOutputStream();
// While there are still bytes in the file, read them and write them
// to our OutputStream
while ((read = fis.read(bytes)) != -1) {
os.write(bytes, 0, read);
}
I read about a solution to add a hidden panel and redirect it to an existing file. But I don't want to create the file on the server, I just want to have the file in a stream.
Is that possible? If yes how?
thanks for helping