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