You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Christian Haul <ha...@informatik.tu-darmstadt.de> on 2003/12/09 14:56:20 UTC

Re: flow: how to upload images into a database

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.

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


Re: flow: how to upload images into a database

Posted by Joern Wallstabe <jo...@rostock.igd.fhg.de>.
On Wed, 10 Dec 2003 07:40:43 -0800
Christopher Oliver <re...@verizon.net> wrote:

> 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();
>  

Hi Christopher,

thank's a lot for the example, it helped a lot figuring out how to store an uploaded file.

For the image retrieval  I'm' using now the Databasereader

http://cocoon.apache.org/2.1/userdocs/readers/database-reader.html

which is quite handy.


Regards jörn

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


Re: flow: how to upload images into a database

Posted by Christopher Oliver <re...@verizon.net>.
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 <ha...@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


Re: flow: how to upload images into a database

Posted by Joern Wallstabe <jo...@rostock.igd.fhg.de>.
On Tue, 09 Dec 2003 14:56:20 +0100
Christian Haul <ha...@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