Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Download File From MySQL BLOB

843854Aug 25 2004 — edited Aug 26 2004
I have written code to successfully upload files of all types to a MySQL database BLOB column. Does anyone have any working code that successfully downloads a file from the MySQL database BLOB column and prompts the user with a Save/Open dialog box that does not involve first writing to the filesystem?

I have used the following which works for Microsoft Word files but does not work for Microsoft PowerPoint files. Any suggestions?
String extension = methodToReturnExtension(request);

response.setContentType( "application/octet-stream" );
String fileName = "FileName" + extension;
response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
BufferedInputStream bufferedInputStream = new BufferedInputStream( methodToReturnInputStream() );
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
int start = 0;
int length = 1024;
byte[] buff = new byte[length];

while ( bufferedInputStream.read( buff, start, length ) != -1 )
{
	byteArrayOutputStream.write( buff, start, length );
}

bufferedInputStream.close();
response.setContentLength( byteArrayOutputStream.size() );
response.getOutputStream().write( byteArrayOutputStream.toByteArray() );
response.getOutputStream().flush();
For PowerPoint files it tells me that PowerPoint cannot open this file so I am assuming the data is getting corrupted somehow. Any help would be appreciated.

Thanks,
Jim
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 23 2004
Added on Aug 25 2004
2 comments
495 views