cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Oliver <res1c...@verizon.net>
Subject Re: flow: how to upload images into a database
Date Wed, 10 Dec 2003 15:40:43 GMT
var BUFSIZE = 8192;
// You can allocate a Java byte array like this
var buf = java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, BUFSIZE);
var os = new java.io.ByteArrayOutputStream();
var count;
while ((count = result.read(buf, 0, buf.length)) > 0) {
      os.write(buf, 0, count);
}
os.flush();
var image = os.toByteArray();
 

Joern Wallstabe wrote:

>On Tue, 09 Dec 2003 14:56:20 +0100
>Christian Haul <haul@informatik.tu-darmstadt.de> wrote:
>
>  
>
>>Joern Wallstabe wrote:
>>
>>    
>>
>>>or can I use 
>>>convert, setColumn etc.  from  org.apache.cocoon.util.JDBCTypeConversions ??
>>>      
>>>
>>Guess so. But the input object must be of a supported type (the sample 
>>uses the raw-request-param module for this).
>>
>>	Chris.
>>
>>    
>>
>Hello Chris,
>thanks for the quick reply.
>To get the image into the database i'm using the following
>
>importPackage(Packages.org.apache.cocoon.util);
>    if (my_image != null) { 
>	    var ps=conn.prepareStatement("UPDATE my_table SET image=? WHERE image_id=?");
>	    ps.setString(2,imageID); 
>	    ps.setBinaryStream(1,my_image,my_image_size);
>	    ps.executeUpdate();
>	    ps.close();	
>    }
>
>
>
>To get the image out:
>....
>importPackage(Packages.org.apache.cocoon.util);
>    var ps=conn.prepareStatement("SELECT image  FROM my_table WHERE image_id=?");
>    ps.setString(1,imageID);
>    var rs= ps.executeQuery();
>      
>    if (rs!= null){
>	    if(rs.next()){
>		var result = rs.getBinaryStream(1);		
>	    }
>	    rs.close();
>    }
>    ps.close();	
> ....
>
>How to I have to process the resulting bytearray (var result = rs.getBinaryStream(1);)
to get an  image back ?
>
>Regards jörn
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>For additional commands, e-mail: users-help@cocoon.apache.org
>
>
>  
>



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message