Hi Dwi,

I use oracle 10g and hibernate 3.1. My table (where i store the image) has a column which
is created by default with an emtpy blob .
sql-command:
create table MAILBOXATTACHMENT (
ID number(19,0) not null, VERSION number(10,0) not null,
BLOB blob default empty_blob(), MIMETYPE varchar2(255 char) not null,
FILENAME varchar2(255 char) not null,
DESCRIPTION varchar2(255 char), MAILBOXENTRY_ID number(19,0),
primary key (ID));

When you want to store a file (e.g. image) in db, you got to get the blob-stream from db. When you got the (Blob)Outputstream, you can copy there your inputstream from your file.
At my code it looks like this:

private void createAttachment(Session s, IMailboxEntry entry)
      throws IOException {
             // get file with tapestry
      final IUploadFile file = getFile();
            // create description of file
      final String description = file.getFileName().substring(
file.getFileName().lastIndexOf(".") + 1, file.getFileName().length());

      // create DB entry with emtpy blob (hibernate)
final IActiveOutputAttachment att = getMailboxEntryDao().createAttachment(s,
          file.getFileName(), description, file.getContentType(), entry);
            // get inputstream of file
      final InputStream in = file.getStream();
      try {
// copy inputstream from file into the outputstream of the blob (code of FileUtil.copy(...) is at button of email.)
          FileUtil.copy(in, att.getOutputStream());
      }
      finally {
          if (att != null) {
              att.close();
          }
          if (in != null) {
              in.close();
          }
      }
  }

/**
   * Copy an InputStream in an OutputStream by using a buffer.
   *
   * It is the responsibility of the user of this function to close
   * both streams.
   */
  public static void copy(InputStream in, OutputStream out)
      throws IOException
  {
      byte[] buffer = new byte[4096];
      int read;
      while ((read = in.read(buffer)) != -1) {
          if (read == 0) {
              Thread.yield();
          }
          else {
              out.write(buffer, 0, read);
          }
      }
  }

Thats all. In prinzip its easy.
Prinzip:
1. Get fileinputstream
2. Create db entry with empty blob
3. Fill the fileinputstream into the blob-outputstream
4. save it

This is the way i did it. Maybe there are better solution. Hope this helped.

Rudolf B.



Dwi Ardi Irawan wrote:

if you don't mind, would you give me an example code to store the image in
DB. i've alredy know how the upload(thnx...), but i still confuse about how
we could store the image in the DB (blob type)
thnx....

----- Original Message -----
From: "Rudolf Baloun" <[EMAIL PROTECTED]>
To: "Tapestry users" <[email protected]>
Sent: Monday, February 27, 2006 5:57 PM
Subject: Re: image upload


Hi,

i use the upload component:

http://jakarta.apache.org/tapestry/tapestry/ComponentReference/Upload.html


The component works fine (I store binaryfiles (e.g. images in DB (blog)
too).
Do you have a special question?

-- Rudolf B.


Dwi Ardi Irawan wrote:

does anybony know about image upload  ?
the image is store in database (type : blob)
please help me ?
----- Original Message -----
From: <[EMAIL PROTECTED]>
To: "Tapestry users" <[email protected]>
Sent: Monday, February 27, 2006 5:31 PM
Subject: Re: Editable datagrid




You could have a look at the tapestry table examples:




http://weblogs.java.net/blog/johnreynolds/archive/2004/10/learn_by_teachi_1
.
html


Mensaje citado por "Francisco A. Lozano"
<[EMAIL PROTECTED]>:



Hello,

I've tried but I can't guess how to do it... Is there an easy way of
doing editable datagrids in tapestry, like in ASP.NET or PRADO?

Thanks!!


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to