Ver Mensaje Individual
  #1 (permalink)  
Antiguo 14/09/2011, 10:01
Brolo
 
Fecha de Ingreso: agosto-2010
Mensajes: 2
Antigüedad: 13 años, 8 meses
Puntos: 0
Imagen almacenada como Blob demasiado grande

Buenas tardes.
Llevo días intentando slucionar el problema que tengo entre manos.

Y es que necesito sacar de la base de datos imágenes que se han almacenado (hace casi 20 años xD) en campos blob.

Lo he planteado de la siguiente manera siguiendo algunos ejemplos encontrados:

Leo en trozos de 32K (la limitación para varchar2 de oracle) y escribo dichos trozos a la response del explorador.

Pego el código:

Código PHP:

    
-- Get the blob image
    SELECT FOTO
    INTO   Photo
    FROM   TEMPORAL_FOTO_PERSONAL
    WHERE  P_ID 
p_id;
    
    
len := dbms_lob.getlength(Photo);
    
dbms_output.put_line(len);
    
BEGIN
    
    owa_util
.mime_header('images/gif'FALSE);
    
htp.p('Pragma: no-cache');
    
htp.p('Content-Transfer-Encoding: binary');
    
htp.p('Content-length: ' || len);
    
htp.p('Content-Disposition: attachment; filename= "Foto ' || p_id ||'.gif" ');
    
owa_util.http_header_close;
    
    
chunksize := dbms_lob.getchunksize(Photo);
    if (
chunksize 32767then
        v_amt 
:= (32767 chunksize) * chunksize;
    
end if;
    
    
lob_bytes_remaining := len;
    while (
lob_bytes_remaining 0)
    
        
LOOP
            
if (lob_bytes_remaining v_amtthen
                v_amt 
:= lob_bytes_remaining;
            
end if;        
            
dbms_lob.read(Photov_amtv_offv_raw);
            
htp.prn(utl_raw.cast_to_varchar2(v_raw));

            
v_off := v_off v_amt;
            
lob_bytes_remaining := lob_bytes_remaining v_amt;

        
END LOOP;
 
    
EXCEPTION
      WHEN NO_DATA_FOUND THEN
        emesg 
:= SQLERRM;
        
dbms_output.put_line(emesg);
      
WHEN OTHERS THEN
        emesg 
:= SQLERRM;
        
dbms_output.put_line(emesg);
      
END trap_errmesg;
      
      
DELETE FROM TEMPORAL_FOTO_PERSONAL;
      
COMMIT;
      
    
END
El problema es que cuando las fotos son mayores de 32K aparecen distorisionadas como la siguiente:



Estoy casi seguro que tiene que ver con los punteros de inicio / fin de lectura de cada trozo de la foto... pero llevo muchas horas dándole vueltas a esto y estoy ya casi desesperado.

Alguna ayuda? :(

Muchas gracias de antemano.