cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Hertz <danielhe...@shaw.ca>
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 java.io.BufferedReader(new java.io.InputStreamReader(stream));

    var line;
    while ((line=reader.readLine())!=null)
      buf.append(line).append("\n");

    reader.close();
  }

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

Daniel



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


Mime
View raw message