I am trying to write an application which can upload and download files [Excel, Word etc.] to/from an Oracle 9i database Blob field. I am using Java/JSP for the same.
The upload part works just fine. However, when I try to download the file that I uploaded, I get an error.
A dialog box comes up asking me to Open/Save the file. However, when I try to save it, it says
“Internet Explorer cannot download …..tion=download&planId= testplan from localhost
Internet Explorer was not able to open this Internet Site. The requested site is either unavailable or cannot be found. Please try again later.”
I am using IE 6.0. I tested the same with Firefox browser and was able to download the file.
Can anyone help?
Code:
Following is the code I am using for the same.
/* Code to retrieve from Blob field */
String sqlString = "SELECT PLAN_DOCUMENT_NAME,PLAN_DOCUMENT FROM BRS_PLAN_DESCRIPTION WHERE PLAN_ID = ?";
ps = con.prepareStatement(sqlString);
ps.setString (1,planId);
rs = ps.executeQuery();
while (rs.next()) {
fileBytes = rs.getBytes("PLAN_DOCUMENT");
fileName = rs.getString("PLAN_DOCUMENT_NAME");
}
brsPlanDocument.setPlanId(planId);
brsPlanDocument.setFileName(fileName);
brsPlanDocument.setFileBytes(fileBytes);
/* Code for download */
String fileName = brsPlanDocument.getFileName();
String fileType = fileName.substring(fileName.indexOf(".")+1,fileName.length());
if (fileType.trim().equalsIgnoreCase("txt"))
{
response.setContentType( "text/plain" );
}
else if (fileType.trim().equalsIgnoreCase("doc"))
{
response.setContentType( "application/msword" );
}
else if (fileType.trim().equalsIgnoreCase("xls"))
{
response.setContentType( "application/vnd.ms-excel" );
}
else if (fileType.trim().equalsIgnoreCase("pdf"))
{
response.setContentType( "application/pdf" );
}
else if (fileType.trim().equalsIgnoreCase("ppt"))
{
response.setContentType( "application/ppt" );
}
else
{
response.setContentType( "application/octet-stream" );
}
response.setHeader("Content-Disposition","attachment; filename=\""+fileName+"\"");
response.setHeader("cache-control", "no-cache");
byte[] fileBytes=brsPlanDocument.getFileBytes();
ServletOutputStream outs = response.getOutputStream();
outs.write(fileBytes);
outs.flush();
outs.close();
Discussions
Web tier: servlets, JSP, Web frameworks: Download - file from Database [Blob field] -JSP
-
Download - file from Database [Blob field] -JSP (6 messages)
- Posted by: Aju Venugopalan
- Posted on: April 18 2005 11:03 EDT
Threaded Messages (6)
- Download - file from Database [Blob field] -JSP by Baiju George on April 20 2005 05:12 EDT
- Download - file from Database [Blob field] -JSP by krishna nand on June 17 2005 01:18 EDT
-
Download - file from Database [Blob field] -JSP by Marina Prikaschikova on June 17 2005 03:40 EDT
- Wat brsPlanDocument???? by Arvind Jain on July 09 2008 10:10 EDT
-
Download - file from Database [Blob field] -JSP by Marina Prikaschikova on June 17 2005 03:40 EDT
- Re: Download - file from Database [Blob field] -JSP by waqas rehman on March 10 2009 06:54 EDT
- Download - file from Database [Blob field] -JSP by krishna nand on June 17 2005 01:18 EDT
- Download - file from Database [Blob field] -JSP by M G on April 26 2010 08:11 EDT
-
Download - file from Database [Blob field] -JSP[ Go to top ]
- Posted by: Baiju George
- Posted on: April 20 2005 05:12 EDT
- in response to Aju Venugopalan
Try this
java.sql.Blob blobColumn = rs.getBlob(("PLAN_DOCUMENT");
fileBytes = blobColumn.getBytes(0,(int)blobColumn.length());
Baiju -
Download - file from Database [Blob field] -JSP[ Go to top ]
- Posted by: krishna nand
- Posted on: June 17 2005 01:18 EDT
- in response to Baiju George
Hi,
I'm facing similar kind of problem can any one please help me out.
I'm uploading file as BLOB in database its working fine,
Now I have to download file as BLOB and write to the browser as a Stream.
Can any one help me on this please.
Regards
Krishna -
Download - file from Database [Blob field] -JSP[ Go to top ]
- Posted by: Marina Prikaschikova
- Posted on: June 17 2005 03:40 EDT
- in response to krishna nand
See for example DB taglib in Coldtags suite:
http://www.servletsuite.com/jsp.htm -
Wat brsPlanDocument????[ Go to top ]
- Posted by: Arvind Jain
- Posted on: July 09 2008 10:10 EDT
- in response to Marina Prikaschikova
what is this... please specify.. -
Re: Download - file from Database [Blob field] -JSP[ Go to top ]
- Posted by: waqas rehman
- Posted on: March 10 2009 06:54 EDT
- in response to Baiju George
I am facing the similar issue. Did you find solutions for this problem -
Download - file from Database [Blob field] -JSP[ Go to top ]
- Posted by: M G
- Posted on: April 26 2010 08:11 EDT
- in response to Aju Venugopalan
Is this problem solved? I am facing same problem.