cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Hertz <>
Subject Image upload to postgre database
Date Thu, 01 Dec 2005 20:05:44 GMT
Hi all,

I wonder if someone might help me understand how to upload an image into a Postgre bytea column.

I must apologize that I'm a graphic designer, NOT a programmer, and so find all this java
and script stuff a bit daunting.

I looked at many of the wonderful samples from the distribution (as well as wiki and this
list), and am using, as my model, the 'upload_example.js'/'upload_model.xml' sample from the
blocks/forms section.

That sample is working fine, but instead of uploading the image to my upload directory (configured
in web.xml), I would like to upload it to:

Table Name = 'images_table'
Column 1 = 'image_id' (auto incremented SERIAL type)
Column 2 = 'image_caption' (varchar)
Column 2 = 'image' (bytea)

Essentially, the form has two input fields, corresponding to the same names as the database
columns ('image_caption' for the text box, and 'image' for the file).

How do I tweak the block sample to send the image to a my database, instead of the file system?
(Do I use some sort of ByteArrayOutputStream and/or cocoon.processPipelineTo after the reader.close();?)

Yikes life was easier with just my Wacom tablet! ;-)

Thanks for any guidance and/or samples..

=== Code from original upload_example.js block sample ===

function handleUpload(form) {

  var buf = new java.lang.StringBuffer();
  var uploadWidget = form.lookupWidget("upload");
  if (uploadWidget.getValue() != null) {
    var stream = uploadWidget.getValue().getInputStream();
    var reader = new;

    var line;
    while ((line=reader.readLine())!=null)


/* is this where I need to do some other processing, like taking input stream and sending
to Postgre instead of string */
var output = new;


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message