Re: [Wicket-user] best practice for uploading and using content (images) with wicket?

2006-08-23 Thread Sebastian Pflugbeil

Well, thanks a lot, thats really much more simple then i figured =P. Maybe
any pointers why the stream from the file system doesnt work? ;)


igor.vaynberg wrote:
 
 your problem is not retreiving the data from the db - it is the weird
 stuff
 you try to do when stream it back to the browser. why all the awt image
 stuff? all you have to do is read the byte array from the db and stream it
 back to the browser.
 
 here is some pseudo code
 
 add(new Image(myimage) {
   Resource getResource() { return new ByteArrayResource(getBytesFromDb());
 }
 }
 
  
 
 if you really want to resize the image to 200x200 before storing it in the
 db or creating a thumbnail then i would look over that wiki example and
 extract the resizing logic - but if all you want to do is stream it back
 then the above will do.
 
 -Igor
 
 
 On 8/22/06, Sebastian Pflugbeil 
 [EMAIL PROTECTED] wrote:

  Hi Wicket Team and Wicket Mailinglist!



 As this is my first post on this list, I would like to introduce myself.
 My name is Sebastian and I am working on a university project, comparing
 Java web frameworks. As you might guess, my primary topic is the Wicket
 framework ;). I am not what one would call a programmer or coder, I
 guess.
 Rather someone familiar with the underling concepts, but sometimes a bit
 lots with the actual implementations of a certain language. So please
 excuse
 me, if my questions are stupid ;).



 My problem at this moment is the following. I need to implement a feature
 in wicket that lets me upload images to a webpage and then use those
 images
 to be displayed on certain pages. It doesn't really matter if the images
 are
 stored on the file system or in a database. I am not looking for a
 solution
 to an explicit problem but rather for a best practice that shows how the
 wicket framework supports such a feature.



 I have tried to read up on anything I could find addressing such a
 feature. But everything I got so far is either way beyond my scope of
 understanding, not offering enough to archive the goal or just not
 working
 as I understand it should.



 I have tried to read the example in the wiki (
 http://www.wicket-wiki.org.uk/wiki/index.php/*UploadDownload*http://www.wicket-wiki.org.uk/wiki/index.php/UploadDownload),
 but I can not really follow it. Too many libraries used that are not
 included and overall to confusing for a non professional like myself.

 I did understand the example for the upload in the wikiexamples though.
 No
 problems writing files to disk or even to database, following that
 example
 code.



 My attempt to store images in the Database is looking something like
 this:



 To write to the Database, I use this code sniped:



 public final void onSubmit()

 {

   try

   {

 // get the content of the upload field

 final FileUpload upload_image =
 upload.getFileUpload();



 // create a byte array of the uploaded item

 byte[] bild = upload_image.getBytes();



 if(upload_image != null)

 {

   **write byte[] to database**

 }

   }

   catch (Exception e) { }

 }



 So far so good. Got my byte array stored. The source file is a jpeg
 image.
 I am not sure if I miss some kind cast here to let the system know what
 *sort* of byte array it should use.



 When I try to retrieve the image from the database, I use the following
 code:



   public ResourceReference getImage()

   {

 return new ResourceReference(some.class, bild)

 {

   public BufferedDynamicImageResource newResource()

   {

 try

 {

 // get the byte[] from DB

  byte[] bild = a.getBild();



 // create a buffered image template

  BufferedDynamicImageResource resource = new
 BufferedDynamicImageResource();

  BufferedImage image = new BufferedImage(200,
 200, BufferedImage.TYPE_INT_RGB);



 // transform the byte[] back to an image (does it work that way? How does

 // java know it was a jpeg before and not a gif for example?)

  java.awt.Image i = Toolkit.getDefaultToolkit
 ().createImage(bild);



  // convert image to buffered image

  image.getGraphics().drawImage(i, 0, 0,
 null);



  Graphics g = image.getGraphics();

  g.drawImage(i, 0, 0, null);

  g.dispose();



 // return the image

  resource.setImage(image);

  return resource;

 }

 catch

[Wicket-user] best practice for uploading and using content (images) with wicket?

2006-08-22 Thread Sebastian Pflugbeil
);

 add(bild);

 bild.add(new
SimpleAttributeModifier(src, url));





which just leads to a runtime exception, I fail to understand.
Something about not being able to stream the object, I think.



Once again, I am sure the problem is just based on my
lack of java skills, rather then by anything wicket does, but never the less
the question stands: Is there anything wicket can do for me in that situation
to make my life easier and maybe even get the things done I want to do? What would
be the best practice to archive the goal, using wicket? My current solution is
a second webserver to which I upload the imagefiles and then refer them via URL
in wicket, pretty much like I would, using PHP. But I guess that cannot be it,
can it?



Thanks in advance for anyone taking the time to read
this or even give me a few pointers. Sorry if my lack of java knowledge causes
most of my problems. Please feel free to point me to any resource filling me in
on what I am missing.



Regards,

Sebastian Pflugbeil












































-
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnkkid=120709bid=263057dat=121642___
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user