hi, i want to upload a image from wicket and store it into dabase, how can i display it?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

hi, i want to upload a image from wicket and store it into dabase, how can i display it?

shrimpy
hi, i want to upload a image from wicket and store it into dabase, how can i display it?

in hibernate, i define the type as  Blob to store the image,
however, when i try to read it,
get the input stream from blob

it always complain that after serialzation, blog may not be asscessable.

/////
item.add(new Image("imgItem", new Resource() {

                        @Override
                        public IResourceStream getResourceStream() {
                            return new AbstractResourceStream() {

                                public InputStream getInputStream() throws ResourceStreamNotFoundException {
                                                       return blob.getBinaryInputStream();
                                                         }

                                public void close() throws IOException {
                                    // close input stream
                                }
                            };
                        }
                    }) );

////

can anybody give me any suggestion,

Thanks.....
Reply | Threaded
Open this post in threaded view
|

Re: hi, i want to upload a image from wicket and store it into dabase, how can i display it?

Nino Saturnino Martinez Vazquez Wael
Search the forum:)

http://markmail.org/message/hgkugvqm6x2hj3j5#query:wicket%20image%20webresource+page:1+mid:hgkugvqm6x2hj3j5+state:results
 

You could also just inject the provider and serve it if not loaded, eg
the method above + injection, I think thats the best option, as it
should be cluster safe..

or this:

package zeuzgroup.application.utils;

import java.awt.image.BufferedImage;

import org.apache.wicket.markup.html.image.resource.DynamicImageResource;

public class ImageResource extends DynamicImageResource {

    // has to save this. or get the image another way!
    private byte[] image;

    public ImageResource(byte[] image, String format) {
        this.image = image;
        setFormat(format);
    }

    public ImageResource(BufferedImage image) {
        this.image = toImageData(image);
    }

    @Override
    protected byte[] getImageData() {
        if (image != null) {
            return image;
        } else {
            return new byte[0];
        }

    }

    /**
     * 1 day!
     */
    @Override
    protected int getCacheDuration() {
       
        return 3600*24;
    }

}
 

shrimpywu wrote:

> hi, i want to upload a image from wicket and store it into dabase, how can i
> display it?
>
> in hibernate, i define the type as  Blob to store the image,
> however, when i try to read it,
> get the input stream from blob
>
> it always complain that after serialzation, blog may not be asscessable.
>
> /////
> item.add(new Image("imgItem", new Resource() {
>
>                         @Override
>                         public IResourceStream getResourceStream() {
>                             return new AbstractResourceStream() {
>
>                                 public InputStream getInputStream() throws
> ResourceStreamNotFoundException {
>                                                        return
> blob.getBinaryInputStream();
>                                                          }
>
>                                 public void close() throws IOException {
>                                     // close input stream
>                                 }
>                             };
>                         }
>                     }) );
>
> ////
>
> can anybody give me any suggestion,
>
> Thanks.....
>  

--
-Wicket for love

Nino Martinez Wael
Java Specialist @ Jayway DK
http://www.jayway.dk
+45 2936 7684


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: hi, i want to upload a image from wicket and store it into dabase, how can i display it?

shrimpy
Thanks for your reply, i have seen that post,

the thing is , i can not get the byte array anyway..

coz i can not asscess the blob object...-_-!!!....even though i saw the post that can use the byte array or inputstream to show the image....






Nino.Martinez wrote
Search the forum:)

http://markmail.org/message/hgkugvqm6x2hj3j5#query:wicket%20image%20webresource+page:1+mid:hgkugvqm6x2hj3j5+state:results
 

You could also just inject the provider and serve it if not loaded, eg
the method above + injection, I think thats the best option, as it
should be cluster safe..

or this:

package zeuzgroup.application.utils;

import java.awt.image.BufferedImage;

import org.apache.wicket.markup.html.image.resource.DynamicImageResource;

public class ImageResource extends DynamicImageResource {

    // has to save this. or get the image another way!
    private byte[] image;

    public ImageResource(byte[] image, String format) {
        this.image = image;
        setFormat(format);
    }

    public ImageResource(BufferedImage image) {
        this.image = toImageData(image);
    }

    @Override
    protected byte[] getImageData() {
        if (image != null) {
            return image;
        } else {
            return new byte[0];
        }

    }

    /**
     * 1 day!
     */
    @Override
    protected int getCacheDuration() {
       
        return 3600*24;
    }

}
 

shrimpywu wrote:
> hi, i want to upload a image from wicket and store it into dabase, how can i
> display it?
>
> in hibernate, i define the type as  Blob to store the image,
> however, when i try to read it,
> get the input stream from blob
>
> it always complain that after serialzation, blog may not be asscessable.
>
> /////
> item.add(new Image("imgItem", new Resource() {
>
>                         @Override
>                         public IResourceStream getResourceStream() {
>                             return new AbstractResourceStream() {
>
>                                 public InputStream getInputStream() throws
> ResourceStreamNotFoundException {
>                                                        return
> blob.getBinaryInputStream();
>                                                          }
>
>                                 public void close() throws IOException {
>                                     // close input stream
>                                 }
>                             };
>                         }
>                     }) );
>
> ////
>
> can anybody give me any suggestion,
>
> Thanks.....
>  

--
-Wicket for love

Nino Martinez Wael
Java Specialist @ Jayway DK
http://www.jayway.dk
+45 2936 7684


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Reply | Threaded
Open this post in threaded view
|

Re: hi, i want to upload a image from wicket and store it into dabase, how can i display it?

James Carman
In reply to this post by Nino Saturnino Martinez Vazquez Wael
I don't know that I would cache the image data.  That will get stored
in the session.  Why use a DynamicImageResource if you're going to
cache (store it in a member variable) the image data anyway?  If the
data comes from the database, then look it up when the resource is
requested.

On Sun, Oct 19, 2008 at 4:42 AM, Nino Saturnino Martinez Vazquez Wael
<[hidden email]> wrote:

> Search the forum:)
>
> http://markmail.org/message/hgkugvqm6x2hj3j5#query:wicket%20image%20webresource+page:1+mid:hgkugvqm6x2hj3j5+state:results
>
>
> You could also just inject the provider and serve it if not loaded, eg the
> method above + injection, I think thats the best option, as it should be
> cluster safe..
>
> or this:
>
> package zeuzgroup.application.utils;
>
> import java.awt.image.BufferedImage;
>
> import org.apache.wicket.markup.html.image.resource.DynamicImageResource;
>
> public class ImageResource extends DynamicImageResource {
>
>   // has to save this. or get the image another way!
>   private byte[] image;
>
>   public ImageResource(byte[] image, String format) {
>       this.image = image;
>       setFormat(format);
>   }
>
>   public ImageResource(BufferedImage image) {
>       this.image = toImageData(image);
>   }
>
>   @Override
>   protected byte[] getImageData() {
>       if (image != null) {
>           return image;
>       } else {
>           return new byte[0];
>       }
>
>   }
>
>   /**
>    * 1 day!
>    */
>   @Override
>   protected int getCacheDuration() {
>             return 3600*24;
>   }
>
> }
>
>
> shrimpywu wrote:
>>
>> hi, i want to upload a image from wicket and store it into dabase, how can
>> i
>> display it?
>>
>> in hibernate, i define the type as  Blob to store the image,
>> however, when i try to read it,
>> get the input stream from blob
>>
>> it always complain that after serialzation, blog may not be asscessable.
>>
>> /////
>> item.add(new Image("imgItem", new Resource() {
>>
>>                        @Override
>>                        public IResourceStream getResourceStream() {
>>                            return new AbstractResourceStream() {
>>
>>                                public InputStream getInputStream() throws
>> ResourceStreamNotFoundException {
>>                                                       return
>> blob.getBinaryInputStream();
>>                                                         }
>>
>>                                public void close() throws IOException {
>>                                    // close input stream
>>                                }
>>                            };
>>                        }
>>                    }) );
>>
>> ////
>>
>> can anybody give me any suggestion,
>>
>> Thanks.....
>>
>
> --
> -Wicket for love
>
> Nino Martinez Wael
> Java Specialist @ Jayway DK
> http://www.jayway.dk
> +45 2936 7684
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: hi, i want to upload a image from wicket and store it into dabase, how can i display it?

Nino Saturnino Martinez Vazquez Wael


James Carman wrote:
> I don't know that I would cache the image data.  That will get stored
> in the session.  Why use a DynamicImageResource if you're going to
> cache (store it in a member variable) the image data anyway?
Well, sure.. And it's not cluster safe.. There are pros and cons to
it... As with everything..

>   If the
> data comes from the database, then look it up when the resource is
> requested.
>  
> On Sun, Oct 19, 2008 at 4:42 AM, Nino Saturnino Martinez Vazquez Wael
> <[hidden email]> wrote:
>  
>> Search the forum:)
>>
>> http://markmail.org/message/hgkugvqm6x2hj3j5#query:wicket%20image%20webresource+page:1+mid:hgkugvqm6x2hj3j5+state:results
>>
>>
>> You could also just inject the provider and serve it if not loaded, eg the
>> method above + injection, I think thats the best option, as it should be
>> cluster safe..
>>
>> or this:
>>
>> package zeuzgroup.application.utils;
>>
>> import java.awt.image.BufferedImage;
>>
>> import org.apache.wicket.markup.html.image.resource.DynamicImageResource;
>>
>> public class ImageResource extends DynamicImageResource {
>>
>>   // has to save this. or get the image another way!
>>   private byte[] image;
>>
>>   public ImageResource(byte[] image, String format) {
>>       this.image = image;
>>       setFormat(format);
>>   }
>>
>>   public ImageResource(BufferedImage image) {
>>       this.image = toImageData(image);
>>   }
>>
>>   @Override
>>   protected byte[] getImageData() {
>>       if (image != null) {
>>           return image;
>>       } else {
>>           return new byte[0];
>>       }
>>
>>   }
>>
>>   /**
>>    * 1 day!
>>    */
>>   @Override
>>   protected int getCacheDuration() {
>>             return 3600*24;
>>   }
>>
>> }
>>
>>
>> shrimpywu wrote:
>>    
>>> hi, i want to upload a image from wicket and store it into dabase, how can
>>> i
>>> display it?
>>>
>>> in hibernate, i define the type as  Blob to store the image,
>>> however, when i try to read it,
>>> get the input stream from blob
>>>
>>> it always complain that after serialzation, blog may not be asscessable.
>>>
>>> /////
>>> item.add(new Image("imgItem", new Resource() {
>>>
>>>                        @Override
>>>                        public IResourceStream getResourceStream() {
>>>                            return new AbstractResourceStream() {
>>>
>>>                                public InputStream getInputStream() throws
>>> ResourceStreamNotFoundException {
>>>                                                       return
>>> blob.getBinaryInputStream();
>>>                                                         }
>>>
>>>                                public void close() throws IOException {
>>>                                    // close input stream
>>>                                }
>>>                            };
>>>                        }
>>>                    }) );
>>>
>>> ////
>>>
>>> can anybody give me any suggestion,
>>>
>>> Thanks.....
>>>
>>>      
>> --
>> -Wicket for love
>>
>> Nino Martinez Wael
>> Java Specialist @ Jayway DK
>> http://www.jayway.dk
>> +45 2936 7684
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>
>>    
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>  

--
-Wicket for love

Nino Martinez Wael
Java Specialist @ Jayway DK
http://www.jayway.dk
+45 2936 7684


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: hi, i want to upload a image from wicket and store it into dabase, how can i display it?

Nino Saturnino Martinez Vazquez Wael
In reply to this post by shrimpy


shrimpywu wrote:
> Thanks for your reply, i have seen that post,
>
> the thing is , i can not get the byte array anyway..
>
> coz i can not asscess the blob object...-_-!!!....even though i saw the post
> that can use the byte array or inputstream to show the image....
>  
? You need to explain that.. Inject the hibernate provider into the
webresource and look up the blob?

>
>
>
>
>
>
> Nino.Martinez wrote:
>  
>> Search the forum:)
>>
>> http://markmail.org/message/hgkugvqm6x2hj3j5#query:wicket%20image%20webresource+page:1+mid:hgkugvqm6x2hj3j5+state:results
>>  
>>
>> You could also just inject the provider and serve it if not loaded, eg
>> the method above + injection, I think thats the best option, as it
>> should be cluster safe..
>>
>> or this:
>>
>> package zeuzgroup.application.utils;
>>
>> import java.awt.image.BufferedImage;
>>
>> import org.apache.wicket.markup.html.image.resource.DynamicImageResource;
>>
>> public class ImageResource extends DynamicImageResource {
>>
>>     // has to save this. or get the image another way!
>>     private byte[] image;
>>
>>     public ImageResource(byte[] image, String format) {
>>         this.image = image;
>>         setFormat(format);
>>     }
>>
>>     public ImageResource(BufferedImage image) {
>>         this.image = toImageData(image);
>>     }
>>
>>     @Override
>>     protected byte[] getImageData() {
>>         if (image != null) {
>>             return image;
>>         } else {
>>             return new byte[0];
>>         }
>>
>>     }
>>
>>     /**
>>      * 1 day!
>>      */
>>     @Override
>>     protected int getCacheDuration() {
>>        
>>         return 3600*24;
>>     }
>>
>> }
>>  
>>
>> shrimpywu wrote:
>>    
>>> hi, i want to upload a image from wicket and store it into dabase, how
>>> can i
>>> display it?
>>>
>>> in hibernate, i define the type as  Blob to store the image,
>>> however, when i try to read it,
>>> get the input stream from blob
>>>
>>> it always complain that after serialzation, blog may not be asscessable.
>>>
>>> /////
>>> item.add(new Image("imgItem", new Resource() {
>>>
>>>                         @Override
>>>                         public IResourceStream getResourceStream() {
>>>                             return new AbstractResourceStream() {
>>>
>>>                                 public InputStream getInputStream()
>>> throws
>>> ResourceStreamNotFoundException {
>>>                                                        return
>>> blob.getBinaryInputStream();
>>>                                                          }
>>>
>>>                                 public void close() throws IOException {
>>>                                     // close input stream
>>>                                 }
>>>                             };
>>>                         }
>>>                     }) );
>>>
>>> ////
>>>
>>> can anybody give me any suggestion,
>>>
>>> Thanks.....
>>>  
>>>      
>> --
>> -Wicket for love
>>
>> Nino Martinez Wael
>> Java Specialist @ Jayway DK
>> http://www.jayway.dk
>> +45 2936 7684
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>
>>
>>    
>
>  

--
-Wicket for love

Nino Martinez Wael
Java Specialist @ Jayway DK
http://www.jayway.dk
+45 2936 7684


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]