Base64 : converter BLOB para imagem JSP

0 respostas
E

Olá estou tentado recuperar uma imagem de um campo BLOB(Oracle) e exibir no jsp, segue abaixo o código.
Já pesquisei no forúm antes e não rolou de forma alguma.

Método que recupera o BLOB:

public void setImagem(BLOB imagem){
		
		String im = new String();		
		
		File outputBinaryFile1 = new File("teste.jpeg");
		  
		long                blobLength;
        long                position;
        int                 chunkSize;
        byte[]              binaryBuffer;
        int                 bytesRead                   = 0;
        int                 totbytesRead                = 0;
        int                 totbytesWritten             = 0;
		try {
			
			FileOutputStream outputFileOutputStream  = new FileOutputStream(outputBinaryFile1);
			
			 blobLength = imagem.length();
	         chunkSize = imagem.getChunkSize();
	         binaryBuffer = new byte[chunkSize];
			
	         for (position = 1; position <= blobLength; position += chunkSize) {
	             bytesRead = imagem.getBytes(position, chunkSize, binaryBuffer);

	             outputFileOutputStream.write(binaryBuffer, 0, bytesRead);
             
	             totbytesRead += bytesRead;
	             totbytesWritten += bytesRead;
   
	         }
	         
	         System.out.println( "\n" +
	                 "==========================================================\n" +
	                 totbytesRead + " bytes read.\n" +
	                 totbytesWritten + " bytes written.\n"+
	                 "==========================================================\n"
	             );
	       	         
	        BASE64Encoder encod = new BASE64Encoder();
	        
             /*
              RESPONSÁVEL PELO ENCODE DO ARRAY  PARA STRING
           */

	         im = encod.encodeBuffer(binaryBuffer);

	         
	         outputFileOutputStream.close();
						
		} catch (SQLException e) {

			e.printStackTrace();
		} catch (FileNotFoundException e) {

			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
						
								
		this.imagem = im;
	}
codigo da jsp:
img src="data:image/jpeg;base64, ${clientes.imagem}" /
OBS: Testei com Base64 da apache e BASE64Encoder da Sun

ele gera a String, porém não aparece imagem, não vou por aString pois é muito grande.

VALEW PESSOAL!

Criado 3 de janeiro de 2011
Respostas 0
Participantes 1