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