You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Rich M <ri...@moremagic.com> on 2011/03/10 20:37:29 UTC

Uploading then displaying Images

Hi,

I think I've run into a conceptual understanding roadblock in trying to 
setup uploading then displaying of images in my application.

I've got the uploading part working so far, although since my 
application is deployed as a WAR, the files upload to a system folder. 
That works alright, but might be a concern regarding the subsequent 
displaying.

I wrote up a service that can manage these images as Image or File 
object, and I wrote up an ImageStreamResponse class with its inputStream 
coming from the Image's outputStream. The service can generate the 
ImageStreamResponse from a filename, which I store in the database.

I had read this thread 
http://tapestry.1045711.n5.nabble.com/How-to-display-Blob-byte-array-image-td2436148.html 
along with other information regarding uploading/displaying images. I 
think I'm a bit confused as to what my ImageStreamResponse is or should 
be achieving. I had thought using that I might be able to display the 
image itself in the TML, but it seems I'd need the URL instead. If I had 
the URL in any case then what purpose does the ImageStreamResponse serve?

Thanks,
Rich

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


Re: Uploading then displaying Images

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Thu, 10 Mar 2011 22:02:04 -0300, Josh Canfield <jo...@gmail.com>  
wrote:

>> Sorry, but that's a really bad advice - never put uploaded files under
>> the context path of your application. What happens when you update the
>> WAR?
>
> Strongly agree.

I agree too. I put my uploaded files in the database. I was just trying to  
explain to Richard some Java web development concepts he seems to not  
having understood yet.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

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


Re: Uploading then displaying Images

Posted by Josh Canfield <jo...@gmail.com>.
>            public InputStream *getStream*() throws IOException {
>                User user =
> (User)_request.getSession(true).getAttribute("user");
>                return user.getImage();
>            }

It looks like you're pulling the User object from the session and then
getting the InputStream from user.getImage();
If user.getImage is caching the stream reference then the stream will
be empty the second time you try to read from it right? Because it's
the same object stored in the session.

Josh

On Fri, Aug 5, 2011 at 1:39 PM, David Canteros
<da...@gmail.com> wrote:
> Hi
> I have to show a image loaded from database BLOB field. I implemented
> Thiago's suggestion, I have created a page with the following code:
>
> public class ShowImagePage {
>
>    @Inject
>    private LinkSource linkSource;
>     (...)
>
>    public Link *getUploadedFile*(String imageId) {
>            return
> linkSource.createPageRenderLink(DisplayImagePage.class.getSimpleName(),
> false, new Object[]{imageId});
>    }
>
>    public StreamResponse *onActivate*(String imageId) {
>        this.filename = imageId;
>        return new StreamResponse() {
>
>            public String *getContentType*() {
>                return contentType;
>            }
>
>            public InputStream *getStream*() throws IOException {
>                User user =
> (User)_request.getSession(true).getAttribute("user");
>                return user.getImage();
>            }
>
>            public void *prepareResponse*(Response response) {
>                response.setHeader("Content-Disposition", "inline;
> filename=" + filename
>                            + ((extension == null) ? "" : ("." +
> extension)));
>            }
>        };
>    }
>  }
> **
> In the javacode of the page where i have to show the image, I injected the
> above page and wrote this method
>
> public Link *getImageLink*(ImageId){
>    return showImagewPage.getUploadedFile(imageId);
> }
>  and in html code I put this:
>
> <img src="${imageLInk}"/>
>
> It works fine, the image is showed but when I refresh the page (with F5),
> the image dissapear. It behavior does not occur if I submit some form placed
> in the same page that refresh the page too (the method  "onSubmitFrom..."
> returns "this" ). I have debugged the code and everything works fine, do you
> have any idea about this behavior?
>
> Thanks!!
>
> ------------------------------------------------------------------
> David Germán Canteros
>
>
> 2011/3/11 Rich M <ri...@moremagic.com>
>
>> Thanks everyone for the responses so far, conceptually I think this is
>> coming together for me.
>>
>> So, I'm glad the context path was not a good idea, it felt dirty from the
>> beginning. Avoiding that, there are two main options: use the database to
>> store/retrieve the images, or use a configured system folder from where I
>> can load/save files with Java IO.
>>
>> Regardless of the option chosen there, the image file will be captured as
>> an InputStream and returned as a StreamResponse in some form to a
>> page/component.
>>
>> As far as linking the StreamResponse to an HTML IMG tag, I believe I
>> understand the various options presented here.
>>
>> LLTYK suggests using an EventLink. I was looking through my code and found
>> a Captcha implementation I have using a propertyExpression in the TML on the
>> src attribute of <IMG> to reference a getImageLink function that returns
>> ComponentResources.**createActionLink("image",null)**. Then there is an
>> onImage() action handler method that returns a StreamResponse. I understand
>> this is ActionLink and not EventLink, but I think the concept must be nearly
>> identical.
>>
>> Alternately, Thiago is suggesting that instead of using ComponentResources
>> to generate an ActionLink or EventLink, it may be easier to create a
>> seperate Page that handles returning just a StreamResponse. In that case the
>> EventLink can be replaced with a PageLink and using an activation context
>> the ID for the Image can be passed to the Page so it can load the Image,
>> build the StreamResponse, and return it.
>>
>> <30 minutes later> Okay, the PageLink works out, great! I can see the
>> biggest issue I was having was setting up the src attribute for IMG
>> correctly. I was stuck thinking it was either the URL to the context path or
>> the StreamResponse itself, rather than a link to an event or page that
>> returns the StreamResponse.
>>
>> Thanks,
>> Rich
>>
>>
>>
>> On 03/11/2011 08:08 AM, Thiago H. de Paula Figueiredo wrote:
>>
>>> On Fri, 11 Mar 2011 09:24:35 -0300, LLTYK <LL...@mailinator.com> wrote:
>>>
>>>  Nobody's mentioned createEventLink. That's where you get the image url,
>>>> create an event link pointing to the event handler that returns the
>>>> stream response.
>>>>
>>>
>>> I haven't mentioned it because my preferred approach is to create a page
>>> just for returning StreamResponses. It's more reusable, as it can be used to
>>> serve images for any page, while an event must be only used inside a give
>>> page.
>>>
>>>
>>
>> ------------------------------**------------------------------**---------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.**apache.org<us...@tapestry.apache.org>
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>

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


Re: Uploading then displaying Images

Posted by Josh Canfield <jo...@gmail.com>.
Ah, good to hear!

On Mon, Aug 8, 2011 at 5:52 AM, David Canteros
<da...@gmail.com> wrote:
> Hi again Josh, i had not  seen your first response, there was the solution to
> my problem.
> Thank you!
> David
>
>
>
> ------------------------------------------------------------------
> David Germán Canteros
>
>
> 2011/8/6 David Canteros <da...@gmail.com>
>
>> Yes, user is an object loaded in the setupRender() method, and getImage()
>> returns an InputStream every time the page is loaded.
>>
>>
>> ------------------------------------------------------------------
>> David Germán Canteros
>>
>>
>> 2011/8/5 Josh Canfield <jo...@gmail.com>
>>
>>> The real issue is more likely the first point, you're getting your
>>> InputStream from an object from the session. Does calling getImage()
>>> return a new InputStream every time?
>>>
>>> On Fri, Aug 5, 2011 at 2:44 PM, David Canteros
>>> <da...@gmail.com> wrote:
>>> > Hi Josh;
>>> >           I have already tried with PageRenderLinkSource but It has the
>>> > same behavior.  I did not know the difference between LinkSource and
>>> > PageRenderLinkSource, thanks for the information!
>>> >
>>> > David
>>> >
>>> > ------------------------------------------------------------------
>>> > David Germán Canteros
>>> >
>>> >
>>> > 2011/8/5 Josh Canfield <jo...@gmail.com>
>>> >
>>> >> Also.
>>> >> >    private LinkSource linkSource;
>>> >>
>>> >> This is an internal class, you should be using PageRenderLinkSource.
>>> >> You can replace:
>>> >>
>>> >> >
>>> linkSource.createPageRenderLink(DisplayImagePage.class.getSimpleName(),
>>> >> false, new Object[]{imageId});
>>> >>
>>> >> with
>>> >>
>>> >>
>>> >>
>>> pageRenderLinkSource.createPageRenderLinkWithContext(DisplayImagePage.class,
>>> >> imageId);
>>> >>
>>> >> Josh
>>> >>
>>> >> On Fri, Aug 5, 2011 at 1:39 PM, David Canteros
>>> >> <da...@gmail.com> wrote:
>>> >> > Hi
>>> >> > I have to show a image loaded from database BLOB field. I implemented
>>> >> > Thiago's suggestion, I have created a page with the following code:
>>> >> >
>>> >> > public class ShowImagePage {
>>> >> >
>>> >> >    @Inject
>>> >> >    private LinkSource linkSource;
>>> >> >     (...)
>>> >> >
>>> >> >    public Link *getUploadedFile*(String imageId) {
>>> >> >            return
>>> >> >
>>> linkSource.createPageRenderLink(DisplayImagePage.class.getSimpleName(),
>>> >> > false, new Object[]{imageId});
>>> >> >    }
>>> >> >
>>> >> >    public StreamResponse *onActivate*(String imageId) {
>>> >> >        this.filename = imageId;
>>> >> >        return new StreamResponse() {
>>> >> >
>>> >> >            public String *getContentType*() {
>>> >> >                return contentType;
>>> >> >            }
>>> >> >
>>> >> >            public InputStream *getStream*() throws IOException {
>>> >> >                User user =
>>> >> > (User)_request.getSession(true).getAttribute("user");
>>> >> >                return user.getImage();
>>> >> >            }
>>> >> >
>>> >> >            public void *prepareResponse*(Response response) {
>>> >> >                response.setHeader("Content-Disposition", "inline;
>>> >> > filename=" + filename
>>> >> >                            + ((extension == null) ? "" : ("." +
>>> >> > extension)));
>>> >> >            }
>>> >> >        };
>>> >> >    }
>>> >> >  }
>>> >> > **
>>> >> > In the javacode of the page where i have to show the image, I
>>> injected
>>> >> the
>>> >> > above page and wrote this method
>>> >> >
>>> >> > public Link *getImageLink*(ImageId){
>>> >> >    return showImagewPage.getUploadedFile(imageId);
>>> >> > }
>>> >> >  and in html code I put this:
>>> >> >
>>> >> > <img src="${imageLInk}"/>
>>> >> >
>>> >> > It works fine, the image is showed but when I refresh the page (with
>>> F5),
>>> >> > the image dissapear. It behavior does not occur if I submit some form
>>> >> placed
>>> >> > in the same page that refresh the page too (the method
>>>  "onSubmitFrom..."
>>> >> > returns "this" ). I have debugged the code and everything works fine,
>>> do
>>> >> you
>>> >> > have any idea about this behavior?
>>> >> >
>>> >> > Thanks!!
>>> >> >
>>> >> > ------------------------------------------------------------------
>>> >> > David Germán Canteros
>>> >> >
>>> >> >
>>> >> > 2011/3/11 Rich M <ri...@moremagic.com>
>>> >> >
>>> >> >> Thanks everyone for the responses so far, conceptually I think this
>>> is
>>> >> >> coming together for me.
>>> >> >>
>>> >> >> So, I'm glad the context path was not a good idea, it felt dirty
>>> from
>>> >> the
>>> >> >> beginning. Avoiding that, there are two main options: use the
>>> database
>>> >> to
>>> >> >> store/retrieve the images, or use a configured system folder from
>>> where
>>> >> I
>>> >> >> can load/save files with Java IO.
>>> >> >>
>>> >> >> Regardless of the option chosen there, the image file will be
>>> captured
>>> >> as
>>> >> >> an InputStream and returned as a StreamResponse in some form to a
>>> >> >> page/component.
>>> >> >>
>>> >> >> As far as linking the StreamResponse to an HTML IMG tag, I believe I
>>> >> >> understand the various options presented here.
>>> >> >>
>>> >> >> LLTYK suggests using an EventLink. I was looking through my code and
>>> >> found
>>> >> >> a Captcha implementation I have using a propertyExpression in the
>>> TML on
>>> >> the
>>> >> >> src attribute of <IMG> to reference a getImageLink function that
>>> returns
>>> >> >> ComponentResources.**createActionLink("image",null)**. Then there is
>>> an
>>> >> >> onImage() action handler method that returns a StreamResponse. I
>>> >> understand
>>> >> >> this is ActionLink and not EventLink, but I think the concept must
>>> be
>>> >> nearly
>>> >> >> identical.
>>> >> >>
>>> >> >> Alternately, Thiago is suggesting that instead of using
>>> >> ComponentResources
>>> >> >> to generate an ActionLink or EventLink, it may be easier to create a
>>> >> >> seperate Page that handles returning just a StreamResponse. In that
>>> case
>>> >> the
>>> >> >> EventLink can be replaced with a PageLink and using an activation
>>> >> context
>>> >> >> the ID for the Image can be passed to the Page so it can load the
>>> Image,
>>> >> >> build the StreamResponse, and return it.
>>> >> >>
>>> >> >> <30 minutes later> Okay, the PageLink works out, great! I can see
>>> the
>>> >> >> biggest issue I was having was setting up the src attribute for IMG
>>> >> >> correctly. I was stuck thinking it was either the URL to the context
>>> >> path or
>>> >> >> the StreamResponse itself, rather than a link to an event or page
>>> that
>>> >> >> returns the StreamResponse.
>>> >> >>
>>> >> >> Thanks,
>>> >> >> Rich
>>> >> >>
>>> >> >>
>>> >> >>
>>> >> >> On 03/11/2011 08:08 AM, Thiago H. de Paula Figueiredo wrote:
>>> >> >>
>>> >> >>> On Fri, 11 Mar 2011 09:24:35 -0300, LLTYK <LL...@mailinator.com>
>>> >> wrote:
>>> >> >>>
>>> >> >>>  Nobody's mentioned createEventLink. That's where you get the image
>>> >> url,
>>> >> >>>> create an event link pointing to the event handler that returns
>>> the
>>> >> >>>> stream response.
>>> >> >>>>
>>> >> >>>
>>> >> >>> I haven't mentioned it because my preferred approach is to create a
>>> >> page
>>> >> >>> just for returning StreamResponses. It's more reusable, as it can
>>> be
>>> >> used to
>>> >> >>> serve images for any page, while an event must be only used inside
>>> a
>>> >> give
>>> >> >>> page.
>>> >> >>>
>>> >> >>>
>>> >> >>
>>> >> >>
>>> >>
>>> ------------------------------**------------------------------**---------
>>> >> >> To unsubscribe, e-mail: users-unsubscribe@tapestry.**apache.org<
>>> >> users-unsubscribe@tapestry.apache.org>
>>> >> >> For additional commands, e-mail: users-help@tapestry.apache.org
>>> >> >>
>>> >> >>
>>> >> >
>>> >>
>>> >> ---------------------------------------------------------------------
>>> >> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> >> For additional commands, e-mail: users-help@tapestry.apache.org
>>> >>
>>> >>
>>> >
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>
>>>
>>
>

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


Re: Uploading then displaying Images

Posted by David Canteros <da...@gmail.com>.
Hi again Josh, i had not  seen your first response, there was the solution to
my problem.
Thank you!
David



------------------------------------------------------------------
David Germán Canteros


2011/8/6 David Canteros <da...@gmail.com>

> Yes, user is an object loaded in the setupRender() method, and getImage()
> returns an InputStream every time the page is loaded.
>
>
> ------------------------------------------------------------------
> David Germán Canteros
>
>
> 2011/8/5 Josh Canfield <jo...@gmail.com>
>
>> The real issue is more likely the first point, you're getting your
>> InputStream from an object from the session. Does calling getImage()
>> return a new InputStream every time?
>>
>> On Fri, Aug 5, 2011 at 2:44 PM, David Canteros
>> <da...@gmail.com> wrote:
>> > Hi Josh;
>> >           I have already tried with PageRenderLinkSource but It has the
>> > same behavior.  I did not know the difference between LinkSource and
>> > PageRenderLinkSource, thanks for the information!
>> >
>> > David
>> >
>> > ------------------------------------------------------------------
>> > David Germán Canteros
>> >
>> >
>> > 2011/8/5 Josh Canfield <jo...@gmail.com>
>> >
>> >> Also.
>> >> >    private LinkSource linkSource;
>> >>
>> >> This is an internal class, you should be using PageRenderLinkSource.
>> >> You can replace:
>> >>
>> >> >
>> linkSource.createPageRenderLink(DisplayImagePage.class.getSimpleName(),
>> >> false, new Object[]{imageId});
>> >>
>> >> with
>> >>
>> >>
>> >>
>> pageRenderLinkSource.createPageRenderLinkWithContext(DisplayImagePage.class,
>> >> imageId);
>> >>
>> >> Josh
>> >>
>> >> On Fri, Aug 5, 2011 at 1:39 PM, David Canteros
>> >> <da...@gmail.com> wrote:
>> >> > Hi
>> >> > I have to show a image loaded from database BLOB field. I implemented
>> >> > Thiago's suggestion, I have created a page with the following code:
>> >> >
>> >> > public class ShowImagePage {
>> >> >
>> >> >    @Inject
>> >> >    private LinkSource linkSource;
>> >> >     (...)
>> >> >
>> >> >    public Link *getUploadedFile*(String imageId) {
>> >> >            return
>> >> >
>> linkSource.createPageRenderLink(DisplayImagePage.class.getSimpleName(),
>> >> > false, new Object[]{imageId});
>> >> >    }
>> >> >
>> >> >    public StreamResponse *onActivate*(String imageId) {
>> >> >        this.filename = imageId;
>> >> >        return new StreamResponse() {
>> >> >
>> >> >            public String *getContentType*() {
>> >> >                return contentType;
>> >> >            }
>> >> >
>> >> >            public InputStream *getStream*() throws IOException {
>> >> >                User user =
>> >> > (User)_request.getSession(true).getAttribute("user");
>> >> >                return user.getImage();
>> >> >            }
>> >> >
>> >> >            public void *prepareResponse*(Response response) {
>> >> >                response.setHeader("Content-Disposition", "inline;
>> >> > filename=" + filename
>> >> >                            + ((extension == null) ? "" : ("." +
>> >> > extension)));
>> >> >            }
>> >> >        };
>> >> >    }
>> >> >  }
>> >> > **
>> >> > In the javacode of the page where i have to show the image, I
>> injected
>> >> the
>> >> > above page and wrote this method
>> >> >
>> >> > public Link *getImageLink*(ImageId){
>> >> >    return showImagewPage.getUploadedFile(imageId);
>> >> > }
>> >> >  and in html code I put this:
>> >> >
>> >> > <img src="${imageLInk}"/>
>> >> >
>> >> > It works fine, the image is showed but when I refresh the page (with
>> F5),
>> >> > the image dissapear. It behavior does not occur if I submit some form
>> >> placed
>> >> > in the same page that refresh the page too (the method
>>  "onSubmitFrom..."
>> >> > returns "this" ). I have debugged the code and everything works fine,
>> do
>> >> you
>> >> > have any idea about this behavior?
>> >> >
>> >> > Thanks!!
>> >> >
>> >> > ------------------------------------------------------------------
>> >> > David Germán Canteros
>> >> >
>> >> >
>> >> > 2011/3/11 Rich M <ri...@moremagic.com>
>> >> >
>> >> >> Thanks everyone for the responses so far, conceptually I think this
>> is
>> >> >> coming together for me.
>> >> >>
>> >> >> So, I'm glad the context path was not a good idea, it felt dirty
>> from
>> >> the
>> >> >> beginning. Avoiding that, there are two main options: use the
>> database
>> >> to
>> >> >> store/retrieve the images, or use a configured system folder from
>> where
>> >> I
>> >> >> can load/save files with Java IO.
>> >> >>
>> >> >> Regardless of the option chosen there, the image file will be
>> captured
>> >> as
>> >> >> an InputStream and returned as a StreamResponse in some form to a
>> >> >> page/component.
>> >> >>
>> >> >> As far as linking the StreamResponse to an HTML IMG tag, I believe I
>> >> >> understand the various options presented here.
>> >> >>
>> >> >> LLTYK suggests using an EventLink. I was looking through my code and
>> >> found
>> >> >> a Captcha implementation I have using a propertyExpression in the
>> TML on
>> >> the
>> >> >> src attribute of <IMG> to reference a getImageLink function that
>> returns
>> >> >> ComponentResources.**createActionLink("image",null)**. Then there is
>> an
>> >> >> onImage() action handler method that returns a StreamResponse. I
>> >> understand
>> >> >> this is ActionLink and not EventLink, but I think the concept must
>> be
>> >> nearly
>> >> >> identical.
>> >> >>
>> >> >> Alternately, Thiago is suggesting that instead of using
>> >> ComponentResources
>> >> >> to generate an ActionLink or EventLink, it may be easier to create a
>> >> >> seperate Page that handles returning just a StreamResponse. In that
>> case
>> >> the
>> >> >> EventLink can be replaced with a PageLink and using an activation
>> >> context
>> >> >> the ID for the Image can be passed to the Page so it can load the
>> Image,
>> >> >> build the StreamResponse, and return it.
>> >> >>
>> >> >> <30 minutes later> Okay, the PageLink works out, great! I can see
>> the
>> >> >> biggest issue I was having was setting up the src attribute for IMG
>> >> >> correctly. I was stuck thinking it was either the URL to the context
>> >> path or
>> >> >> the StreamResponse itself, rather than a link to an event or page
>> that
>> >> >> returns the StreamResponse.
>> >> >>
>> >> >> Thanks,
>> >> >> Rich
>> >> >>
>> >> >>
>> >> >>
>> >> >> On 03/11/2011 08:08 AM, Thiago H. de Paula Figueiredo wrote:
>> >> >>
>> >> >>> On Fri, 11 Mar 2011 09:24:35 -0300, LLTYK <LL...@mailinator.com>
>> >> wrote:
>> >> >>>
>> >> >>>  Nobody's mentioned createEventLink. That's where you get the image
>> >> url,
>> >> >>>> create an event link pointing to the event handler that returns
>> the
>> >> >>>> stream response.
>> >> >>>>
>> >> >>>
>> >> >>> I haven't mentioned it because my preferred approach is to create a
>> >> page
>> >> >>> just for returning StreamResponses. It's more reusable, as it can
>> be
>> >> used to
>> >> >>> serve images for any page, while an event must be only used inside
>> a
>> >> give
>> >> >>> page.
>> >> >>>
>> >> >>>
>> >> >>
>> >> >>
>> >>
>> ------------------------------**------------------------------**---------
>> >> >> To unsubscribe, e-mail: users-unsubscribe@tapestry.**apache.org<
>> >> users-unsubscribe@tapestry.apache.org>
>> >> >> For additional commands, e-mail: users-help@tapestry.apache.org
>> >> >>
>> >> >>
>> >> >
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> >> For additional commands, e-mail: users-help@tapestry.apache.org
>> >>
>> >>
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>

Re: Uploading then displaying Images

Posted by David Canteros <da...@gmail.com>.
Yes, user is an object loaded in the setupRender() method, and getImage()
returns an InputStream every time the page is loaded.


------------------------------------------------------------------
David Germán Canteros


2011/8/5 Josh Canfield <jo...@gmail.com>

> The real issue is more likely the first point, you're getting your
> InputStream from an object from the session. Does calling getImage()
> return a new InputStream every time?
>
> On Fri, Aug 5, 2011 at 2:44 PM, David Canteros
> <da...@gmail.com> wrote:
> > Hi Josh;
> >           I have already tried with PageRenderLinkSource but It has the
> > same behavior.  I did not know the difference between LinkSource and
> > PageRenderLinkSource, thanks for the information!
> >
> > David
> >
> > ------------------------------------------------------------------
> > David Germán Canteros
> >
> >
> > 2011/8/5 Josh Canfield <jo...@gmail.com>
> >
> >> Also.
> >> >    private LinkSource linkSource;
> >>
> >> This is an internal class, you should be using PageRenderLinkSource.
> >> You can replace:
> >>
> >> >
> linkSource.createPageRenderLink(DisplayImagePage.class.getSimpleName(),
> >> false, new Object[]{imageId});
> >>
> >> with
> >>
> >>
> >>
> pageRenderLinkSource.createPageRenderLinkWithContext(DisplayImagePage.class,
> >> imageId);
> >>
> >> Josh
> >>
> >> On Fri, Aug 5, 2011 at 1:39 PM, David Canteros
> >> <da...@gmail.com> wrote:
> >> > Hi
> >> > I have to show a image loaded from database BLOB field. I implemented
> >> > Thiago's suggestion, I have created a page with the following code:
> >> >
> >> > public class ShowImagePage {
> >> >
> >> >    @Inject
> >> >    private LinkSource linkSource;
> >> >     (...)
> >> >
> >> >    public Link *getUploadedFile*(String imageId) {
> >> >            return
> >> >
> linkSource.createPageRenderLink(DisplayImagePage.class.getSimpleName(),
> >> > false, new Object[]{imageId});
> >> >    }
> >> >
> >> >    public StreamResponse *onActivate*(String imageId) {
> >> >        this.filename = imageId;
> >> >        return new StreamResponse() {
> >> >
> >> >            public String *getContentType*() {
> >> >                return contentType;
> >> >            }
> >> >
> >> >            public InputStream *getStream*() throws IOException {
> >> >                User user =
> >> > (User)_request.getSession(true).getAttribute("user");
> >> >                return user.getImage();
> >> >            }
> >> >
> >> >            public void *prepareResponse*(Response response) {
> >> >                response.setHeader("Content-Disposition", "inline;
> >> > filename=" + filename
> >> >                            + ((extension == null) ? "" : ("." +
> >> > extension)));
> >> >            }
> >> >        };
> >> >    }
> >> >  }
> >> > **
> >> > In the javacode of the page where i have to show the image, I injected
> >> the
> >> > above page and wrote this method
> >> >
> >> > public Link *getImageLink*(ImageId){
> >> >    return showImagewPage.getUploadedFile(imageId);
> >> > }
> >> >  and in html code I put this:
> >> >
> >> > <img src="${imageLInk}"/>
> >> >
> >> > It works fine, the image is showed but when I refresh the page (with
> F5),
> >> > the image dissapear. It behavior does not occur if I submit some form
> >> placed
> >> > in the same page that refresh the page too (the method
>  "onSubmitFrom..."
> >> > returns "this" ). I have debugged the code and everything works fine,
> do
> >> you
> >> > have any idea about this behavior?
> >> >
> >> > Thanks!!
> >> >
> >> > ------------------------------------------------------------------
> >> > David Germán Canteros
> >> >
> >> >
> >> > 2011/3/11 Rich M <ri...@moremagic.com>
> >> >
> >> >> Thanks everyone for the responses so far, conceptually I think this
> is
> >> >> coming together for me.
> >> >>
> >> >> So, I'm glad the context path was not a good idea, it felt dirty from
> >> the
> >> >> beginning. Avoiding that, there are two main options: use the
> database
> >> to
> >> >> store/retrieve the images, or use a configured system folder from
> where
> >> I
> >> >> can load/save files with Java IO.
> >> >>
> >> >> Regardless of the option chosen there, the image file will be
> captured
> >> as
> >> >> an InputStream and returned as a StreamResponse in some form to a
> >> >> page/component.
> >> >>
> >> >> As far as linking the StreamResponse to an HTML IMG tag, I believe I
> >> >> understand the various options presented here.
> >> >>
> >> >> LLTYK suggests using an EventLink. I was looking through my code and
> >> found
> >> >> a Captcha implementation I have using a propertyExpression in the TML
> on
> >> the
> >> >> src attribute of <IMG> to reference a getImageLink function that
> returns
> >> >> ComponentResources.**createActionLink("image",null)**. Then there is
> an
> >> >> onImage() action handler method that returns a StreamResponse. I
> >> understand
> >> >> this is ActionLink and not EventLink, but I think the concept must be
> >> nearly
> >> >> identical.
> >> >>
> >> >> Alternately, Thiago is suggesting that instead of using
> >> ComponentResources
> >> >> to generate an ActionLink or EventLink, it may be easier to create a
> >> >> seperate Page that handles returning just a StreamResponse. In that
> case
> >> the
> >> >> EventLink can be replaced with a PageLink and using an activation
> >> context
> >> >> the ID for the Image can be passed to the Page so it can load the
> Image,
> >> >> build the StreamResponse, and return it.
> >> >>
> >> >> <30 minutes later> Okay, the PageLink works out, great! I can see the
> >> >> biggest issue I was having was setting up the src attribute for IMG
> >> >> correctly. I was stuck thinking it was either the URL to the context
> >> path or
> >> >> the StreamResponse itself, rather than a link to an event or page
> that
> >> >> returns the StreamResponse.
> >> >>
> >> >> Thanks,
> >> >> Rich
> >> >>
> >> >>
> >> >>
> >> >> On 03/11/2011 08:08 AM, Thiago H. de Paula Figueiredo wrote:
> >> >>
> >> >>> On Fri, 11 Mar 2011 09:24:35 -0300, LLTYK <LL...@mailinator.com>
> >> wrote:
> >> >>>
> >> >>>  Nobody's mentioned createEventLink. That's where you get the image
> >> url,
> >> >>>> create an event link pointing to the event handler that returns the
> >> >>>> stream response.
> >> >>>>
> >> >>>
> >> >>> I haven't mentioned it because my preferred approach is to create a
> >> page
> >> >>> just for returning StreamResponses. It's more reusable, as it can be
> >> used to
> >> >>> serve images for any page, while an event must be only used inside a
> >> give
> >> >>> page.
> >> >>>
> >> >>>
> >> >>
> >> >>
> >>
> ------------------------------**------------------------------**---------
> >> >> To unsubscribe, e-mail: users-unsubscribe@tapestry.**apache.org<
> >> users-unsubscribe@tapestry.apache.org>
> >> >> For additional commands, e-mail: users-help@tapestry.apache.org
> >> >>
> >> >>
> >> >
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> >> For additional commands, e-mail: users-help@tapestry.apache.org
> >>
> >>
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: Uploading then displaying Images

Posted by Josh Canfield <jo...@gmail.com>.
The real issue is more likely the first point, you're getting your
InputStream from an object from the session. Does calling getImage()
return a new InputStream every time?

On Fri, Aug 5, 2011 at 2:44 PM, David Canteros
<da...@gmail.com> wrote:
> Hi Josh;
>           I have already tried with PageRenderLinkSource but It has the
> same behavior.  I did not know the difference between LinkSource and
> PageRenderLinkSource, thanks for the information!
>
> David
>
> ------------------------------------------------------------------
> David Germán Canteros
>
>
> 2011/8/5 Josh Canfield <jo...@gmail.com>
>
>> Also.
>> >    private LinkSource linkSource;
>>
>> This is an internal class, you should be using PageRenderLinkSource.
>> You can replace:
>>
>> > linkSource.createPageRenderLink(DisplayImagePage.class.getSimpleName(),
>> false, new Object[]{imageId});
>>
>> with
>>
>>
>> pageRenderLinkSource.createPageRenderLinkWithContext(DisplayImagePage.class,
>> imageId);
>>
>> Josh
>>
>> On Fri, Aug 5, 2011 at 1:39 PM, David Canteros
>> <da...@gmail.com> wrote:
>> > Hi
>> > I have to show a image loaded from database BLOB field. I implemented
>> > Thiago's suggestion, I have created a page with the following code:
>> >
>> > public class ShowImagePage {
>> >
>> >    @Inject
>> >    private LinkSource linkSource;
>> >     (...)
>> >
>> >    public Link *getUploadedFile*(String imageId) {
>> >            return
>> > linkSource.createPageRenderLink(DisplayImagePage.class.getSimpleName(),
>> > false, new Object[]{imageId});
>> >    }
>> >
>> >    public StreamResponse *onActivate*(String imageId) {
>> >        this.filename = imageId;
>> >        return new StreamResponse() {
>> >
>> >            public String *getContentType*() {
>> >                return contentType;
>> >            }
>> >
>> >            public InputStream *getStream*() throws IOException {
>> >                User user =
>> > (User)_request.getSession(true).getAttribute("user");
>> >                return user.getImage();
>> >            }
>> >
>> >            public void *prepareResponse*(Response response) {
>> >                response.setHeader("Content-Disposition", "inline;
>> > filename=" + filename
>> >                            + ((extension == null) ? "" : ("." +
>> > extension)));
>> >            }
>> >        };
>> >    }
>> >  }
>> > **
>> > In the javacode of the page where i have to show the image, I injected
>> the
>> > above page and wrote this method
>> >
>> > public Link *getImageLink*(ImageId){
>> >    return showImagewPage.getUploadedFile(imageId);
>> > }
>> >  and in html code I put this:
>> >
>> > <img src="${imageLInk}"/>
>> >
>> > It works fine, the image is showed but when I refresh the page (with F5),
>> > the image dissapear. It behavior does not occur if I submit some form
>> placed
>> > in the same page that refresh the page too (the method  "onSubmitFrom..."
>> > returns "this" ). I have debugged the code and everything works fine, do
>> you
>> > have any idea about this behavior?
>> >
>> > Thanks!!
>> >
>> > ------------------------------------------------------------------
>> > David Germán Canteros
>> >
>> >
>> > 2011/3/11 Rich M <ri...@moremagic.com>
>> >
>> >> Thanks everyone for the responses so far, conceptually I think this is
>> >> coming together for me.
>> >>
>> >> So, I'm glad the context path was not a good idea, it felt dirty from
>> the
>> >> beginning. Avoiding that, there are two main options: use the database
>> to
>> >> store/retrieve the images, or use a configured system folder from where
>> I
>> >> can load/save files with Java IO.
>> >>
>> >> Regardless of the option chosen there, the image file will be captured
>> as
>> >> an InputStream and returned as a StreamResponse in some form to a
>> >> page/component.
>> >>
>> >> As far as linking the StreamResponse to an HTML IMG tag, I believe I
>> >> understand the various options presented here.
>> >>
>> >> LLTYK suggests using an EventLink. I was looking through my code and
>> found
>> >> a Captcha implementation I have using a propertyExpression in the TML on
>> the
>> >> src attribute of <IMG> to reference a getImageLink function that returns
>> >> ComponentResources.**createActionLink("image",null)**. Then there is an
>> >> onImage() action handler method that returns a StreamResponse. I
>> understand
>> >> this is ActionLink and not EventLink, but I think the concept must be
>> nearly
>> >> identical.
>> >>
>> >> Alternately, Thiago is suggesting that instead of using
>> ComponentResources
>> >> to generate an ActionLink or EventLink, it may be easier to create a
>> >> seperate Page that handles returning just a StreamResponse. In that case
>> the
>> >> EventLink can be replaced with a PageLink and using an activation
>> context
>> >> the ID for the Image can be passed to the Page so it can load the Image,
>> >> build the StreamResponse, and return it.
>> >>
>> >> <30 minutes later> Okay, the PageLink works out, great! I can see the
>> >> biggest issue I was having was setting up the src attribute for IMG
>> >> correctly. I was stuck thinking it was either the URL to the context
>> path or
>> >> the StreamResponse itself, rather than a link to an event or page that
>> >> returns the StreamResponse.
>> >>
>> >> Thanks,
>> >> Rich
>> >>
>> >>
>> >>
>> >> On 03/11/2011 08:08 AM, Thiago H. de Paula Figueiredo wrote:
>> >>
>> >>> On Fri, 11 Mar 2011 09:24:35 -0300, LLTYK <LL...@mailinator.com>
>> wrote:
>> >>>
>> >>>  Nobody's mentioned createEventLink. That's where you get the image
>> url,
>> >>>> create an event link pointing to the event handler that returns the
>> >>>> stream response.
>> >>>>
>> >>>
>> >>> I haven't mentioned it because my preferred approach is to create a
>> page
>> >>> just for returning StreamResponses. It's more reusable, as it can be
>> used to
>> >>> serve images for any page, while an event must be only used inside a
>> give
>> >>> page.
>> >>>
>> >>>
>> >>
>> >>
>> ------------------------------**------------------------------**---------
>> >> To unsubscribe, e-mail: users-unsubscribe@tapestry.**apache.org<
>> users-unsubscribe@tapestry.apache.org>
>> >> For additional commands, e-mail: users-help@tapestry.apache.org
>> >>
>> >>
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>

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


Re: Uploading then displaying Images

Posted by David Canteros <da...@gmail.com>.
Hi Josh;
           I have already tried with PageRenderLinkSource but It has the
same behavior.  I did not know the difference between LinkSource and
PageRenderLinkSource, thanks for the information!

David

------------------------------------------------------------------
David Germán Canteros


2011/8/5 Josh Canfield <jo...@gmail.com>

> Also.
> >    private LinkSource linkSource;
>
> This is an internal class, you should be using PageRenderLinkSource.
> You can replace:
>
> > linkSource.createPageRenderLink(DisplayImagePage.class.getSimpleName(),
> false, new Object[]{imageId});
>
> with
>
>
> pageRenderLinkSource.createPageRenderLinkWithContext(DisplayImagePage.class,
> imageId);
>
> Josh
>
> On Fri, Aug 5, 2011 at 1:39 PM, David Canteros
> <da...@gmail.com> wrote:
> > Hi
> > I have to show a image loaded from database BLOB field. I implemented
> > Thiago's suggestion, I have created a page with the following code:
> >
> > public class ShowImagePage {
> >
> >    @Inject
> >    private LinkSource linkSource;
> >     (...)
> >
> >    public Link *getUploadedFile*(String imageId) {
> >            return
> > linkSource.createPageRenderLink(DisplayImagePage.class.getSimpleName(),
> > false, new Object[]{imageId});
> >    }
> >
> >    public StreamResponse *onActivate*(String imageId) {
> >        this.filename = imageId;
> >        return new StreamResponse() {
> >
> >            public String *getContentType*() {
> >                return contentType;
> >            }
> >
> >            public InputStream *getStream*() throws IOException {
> >                User user =
> > (User)_request.getSession(true).getAttribute("user");
> >                return user.getImage();
> >            }
> >
> >            public void *prepareResponse*(Response response) {
> >                response.setHeader("Content-Disposition", "inline;
> > filename=" + filename
> >                            + ((extension == null) ? "" : ("." +
> > extension)));
> >            }
> >        };
> >    }
> >  }
> > **
> > In the javacode of the page where i have to show the image, I injected
> the
> > above page and wrote this method
> >
> > public Link *getImageLink*(ImageId){
> >    return showImagewPage.getUploadedFile(imageId);
> > }
> >  and in html code I put this:
> >
> > <img src="${imageLInk}"/>
> >
> > It works fine, the image is showed but when I refresh the page (with F5),
> > the image dissapear. It behavior does not occur if I submit some form
> placed
> > in the same page that refresh the page too (the method  "onSubmitFrom..."
> > returns "this" ). I have debugged the code and everything works fine, do
> you
> > have any idea about this behavior?
> >
> > Thanks!!
> >
> > ------------------------------------------------------------------
> > David Germán Canteros
> >
> >
> > 2011/3/11 Rich M <ri...@moremagic.com>
> >
> >> Thanks everyone for the responses so far, conceptually I think this is
> >> coming together for me.
> >>
> >> So, I'm glad the context path was not a good idea, it felt dirty from
> the
> >> beginning. Avoiding that, there are two main options: use the database
> to
> >> store/retrieve the images, or use a configured system folder from where
> I
> >> can load/save files with Java IO.
> >>
> >> Regardless of the option chosen there, the image file will be captured
> as
> >> an InputStream and returned as a StreamResponse in some form to a
> >> page/component.
> >>
> >> As far as linking the StreamResponse to an HTML IMG tag, I believe I
> >> understand the various options presented here.
> >>
> >> LLTYK suggests using an EventLink. I was looking through my code and
> found
> >> a Captcha implementation I have using a propertyExpression in the TML on
> the
> >> src attribute of <IMG> to reference a getImageLink function that returns
> >> ComponentResources.**createActionLink("image",null)**. Then there is an
> >> onImage() action handler method that returns a StreamResponse. I
> understand
> >> this is ActionLink and not EventLink, but I think the concept must be
> nearly
> >> identical.
> >>
> >> Alternately, Thiago is suggesting that instead of using
> ComponentResources
> >> to generate an ActionLink or EventLink, it may be easier to create a
> >> seperate Page that handles returning just a StreamResponse. In that case
> the
> >> EventLink can be replaced with a PageLink and using an activation
> context
> >> the ID for the Image can be passed to the Page so it can load the Image,
> >> build the StreamResponse, and return it.
> >>
> >> <30 minutes later> Okay, the PageLink works out, great! I can see the
> >> biggest issue I was having was setting up the src attribute for IMG
> >> correctly. I was stuck thinking it was either the URL to the context
> path or
> >> the StreamResponse itself, rather than a link to an event or page that
> >> returns the StreamResponse.
> >>
> >> Thanks,
> >> Rich
> >>
> >>
> >>
> >> On 03/11/2011 08:08 AM, Thiago H. de Paula Figueiredo wrote:
> >>
> >>> On Fri, 11 Mar 2011 09:24:35 -0300, LLTYK <LL...@mailinator.com>
> wrote:
> >>>
> >>>  Nobody's mentioned createEventLink. That's where you get the image
> url,
> >>>> create an event link pointing to the event handler that returns the
> >>>> stream response.
> >>>>
> >>>
> >>> I haven't mentioned it because my preferred approach is to create a
> page
> >>> just for returning StreamResponses. It's more reusable, as it can be
> used to
> >>> serve images for any page, while an event must be only used inside a
> give
> >>> page.
> >>>
> >>>
> >>
> >>
> ------------------------------**------------------------------**---------
> >> To unsubscribe, e-mail: users-unsubscribe@tapestry.**apache.org<
> users-unsubscribe@tapestry.apache.org>
> >> For additional commands, e-mail: users-help@tapestry.apache.org
> >>
> >>
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: Uploading then displaying Images

Posted by Josh Canfield <jo...@gmail.com>.
Also.
>    private LinkSource linkSource;

This is an internal class, you should be using PageRenderLinkSource.
You can replace:

> linkSource.createPageRenderLink(DisplayImagePage.class.getSimpleName(), false, new Object[]{imageId});

with

pageRenderLinkSource.createPageRenderLinkWithContext(DisplayImagePage.class,
imageId);

Josh

On Fri, Aug 5, 2011 at 1:39 PM, David Canteros
<da...@gmail.com> wrote:
> Hi
> I have to show a image loaded from database BLOB field. I implemented
> Thiago's suggestion, I have created a page with the following code:
>
> public class ShowImagePage {
>
>    @Inject
>    private LinkSource linkSource;
>     (...)
>
>    public Link *getUploadedFile*(String imageId) {
>            return
> linkSource.createPageRenderLink(DisplayImagePage.class.getSimpleName(),
> false, new Object[]{imageId});
>    }
>
>    public StreamResponse *onActivate*(String imageId) {
>        this.filename = imageId;
>        return new StreamResponse() {
>
>            public String *getContentType*() {
>                return contentType;
>            }
>
>            public InputStream *getStream*() throws IOException {
>                User user =
> (User)_request.getSession(true).getAttribute("user");
>                return user.getImage();
>            }
>
>            public void *prepareResponse*(Response response) {
>                response.setHeader("Content-Disposition", "inline;
> filename=" + filename
>                            + ((extension == null) ? "" : ("." +
> extension)));
>            }
>        };
>    }
>  }
> **
> In the javacode of the page where i have to show the image, I injected the
> above page and wrote this method
>
> public Link *getImageLink*(ImageId){
>    return showImagewPage.getUploadedFile(imageId);
> }
>  and in html code I put this:
>
> <img src="${imageLInk}"/>
>
> It works fine, the image is showed but when I refresh the page (with F5),
> the image dissapear. It behavior does not occur if I submit some form placed
> in the same page that refresh the page too (the method  "onSubmitFrom..."
> returns "this" ). I have debugged the code and everything works fine, do you
> have any idea about this behavior?
>
> Thanks!!
>
> ------------------------------------------------------------------
> David Germán Canteros
>
>
> 2011/3/11 Rich M <ri...@moremagic.com>
>
>> Thanks everyone for the responses so far, conceptually I think this is
>> coming together for me.
>>
>> So, I'm glad the context path was not a good idea, it felt dirty from the
>> beginning. Avoiding that, there are two main options: use the database to
>> store/retrieve the images, or use a configured system folder from where I
>> can load/save files with Java IO.
>>
>> Regardless of the option chosen there, the image file will be captured as
>> an InputStream and returned as a StreamResponse in some form to a
>> page/component.
>>
>> As far as linking the StreamResponse to an HTML IMG tag, I believe I
>> understand the various options presented here.
>>
>> LLTYK suggests using an EventLink. I was looking through my code and found
>> a Captcha implementation I have using a propertyExpression in the TML on the
>> src attribute of <IMG> to reference a getImageLink function that returns
>> ComponentResources.**createActionLink("image",null)**. Then there is an
>> onImage() action handler method that returns a StreamResponse. I understand
>> this is ActionLink and not EventLink, but I think the concept must be nearly
>> identical.
>>
>> Alternately, Thiago is suggesting that instead of using ComponentResources
>> to generate an ActionLink or EventLink, it may be easier to create a
>> seperate Page that handles returning just a StreamResponse. In that case the
>> EventLink can be replaced with a PageLink and using an activation context
>> the ID for the Image can be passed to the Page so it can load the Image,
>> build the StreamResponse, and return it.
>>
>> <30 minutes later> Okay, the PageLink works out, great! I can see the
>> biggest issue I was having was setting up the src attribute for IMG
>> correctly. I was stuck thinking it was either the URL to the context path or
>> the StreamResponse itself, rather than a link to an event or page that
>> returns the StreamResponse.
>>
>> Thanks,
>> Rich
>>
>>
>>
>> On 03/11/2011 08:08 AM, Thiago H. de Paula Figueiredo wrote:
>>
>>> On Fri, 11 Mar 2011 09:24:35 -0300, LLTYK <LL...@mailinator.com> wrote:
>>>
>>>  Nobody's mentioned createEventLink. That's where you get the image url,
>>>> create an event link pointing to the event handler that returns the
>>>> stream response.
>>>>
>>>
>>> I haven't mentioned it because my preferred approach is to create a page
>>> just for returning StreamResponses. It's more reusable, as it can be used to
>>> serve images for any page, while an event must be only used inside a give
>>> page.
>>>
>>>
>>
>> ------------------------------**------------------------------**---------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.**apache.org<us...@tapestry.apache.org>
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>

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


Re: Uploading then displaying Images

Posted by David Canteros <da...@gmail.com>.
Hi
I have to show a image loaded from database BLOB field. I implemented
Thiago's suggestion, I have created a page with the following code:

public class ShowImagePage {

    @Inject
    private LinkSource linkSource;
     (...)

    public Link *getUploadedFile*(String imageId) {
            return
linkSource.createPageRenderLink(DisplayImagePage.class.getSimpleName(),
false, new Object[]{imageId});
    }

    public StreamResponse *onActivate*(String imageId) {
        this.filename = imageId;
        return new StreamResponse() {

            public String *getContentType*() {
                return contentType;
            }

            public InputStream *getStream*() throws IOException {
                User user =
(User)_request.getSession(true).getAttribute("user");
                return user.getImage();
            }

            public void *prepareResponse*(Response response) {
                response.setHeader("Content-Disposition", "inline;
filename=" + filename
                            + ((extension == null) ? "" : ("." +
extension)));
            }
        };
    }
 }
**
In the javacode of the page where i have to show the image, I injected the
above page and wrote this method

public Link *getImageLink*(ImageId){
    return showImagewPage.getUploadedFile(imageId);
}
 and in html code I put this:

<img src="${imageLInk}"/>

It works fine, the image is showed but when I refresh the page (with F5),
the image dissapear. It behavior does not occur if I submit some form placed
in the same page that refresh the page too (the method  "onSubmitFrom..."
returns "this" ). I have debugged the code and everything works fine, do you
have any idea about this behavior?

Thanks!!

------------------------------------------------------------------
David Germán Canteros


2011/3/11 Rich M <ri...@moremagic.com>

> Thanks everyone for the responses so far, conceptually I think this is
> coming together for me.
>
> So, I'm glad the context path was not a good idea, it felt dirty from the
> beginning. Avoiding that, there are two main options: use the database to
> store/retrieve the images, or use a configured system folder from where I
> can load/save files with Java IO.
>
> Regardless of the option chosen there, the image file will be captured as
> an InputStream and returned as a StreamResponse in some form to a
> page/component.
>
> As far as linking the StreamResponse to an HTML IMG tag, I believe I
> understand the various options presented here.
>
> LLTYK suggests using an EventLink. I was looking through my code and found
> a Captcha implementation I have using a propertyExpression in the TML on the
> src attribute of <IMG> to reference a getImageLink function that returns
> ComponentResources.**createActionLink("image",null)**. Then there is an
> onImage() action handler method that returns a StreamResponse. I understand
> this is ActionLink and not EventLink, but I think the concept must be nearly
> identical.
>
> Alternately, Thiago is suggesting that instead of using ComponentResources
> to generate an ActionLink or EventLink, it may be easier to create a
> seperate Page that handles returning just a StreamResponse. In that case the
> EventLink can be replaced with a PageLink and using an activation context
> the ID for the Image can be passed to the Page so it can load the Image,
> build the StreamResponse, and return it.
>
> <30 minutes later> Okay, the PageLink works out, great! I can see the
> biggest issue I was having was setting up the src attribute for IMG
> correctly. I was stuck thinking it was either the URL to the context path or
> the StreamResponse itself, rather than a link to an event or page that
> returns the StreamResponse.
>
> Thanks,
> Rich
>
>
>
> On 03/11/2011 08:08 AM, Thiago H. de Paula Figueiredo wrote:
>
>> On Fri, 11 Mar 2011 09:24:35 -0300, LLTYK <LL...@mailinator.com> wrote:
>>
>>  Nobody's mentioned createEventLink. That's where you get the image url,
>>> create an event link pointing to the event handler that returns the
>>> stream response.
>>>
>>
>> I haven't mentioned it because my preferred approach is to create a page
>> just for returning StreamResponses. It's more reusable, as it can be used to
>> serve images for any page, while an event must be only used inside a give
>> page.
>>
>>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.**apache.org<us...@tapestry.apache.org>
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: Uploading then displaying Images

Posted by Rich M <ri...@moremagic.com>.
Thanks everyone for the responses so far, conceptually I think this is 
coming together for me.

So, I'm glad the context path was not a good idea, it felt dirty from 
the beginning. Avoiding that, there are two main options: use the 
database to store/retrieve the images, or use a configured system folder 
from where I can load/save files with Java IO.

Regardless of the option chosen there, the image file will be captured 
as an InputStream and returned as a StreamResponse in some form to a 
page/component.

As far as linking the StreamResponse to an HTML IMG tag, I believe I 
understand the various options presented here.

LLTYK suggests using an EventLink. I was looking through my code and 
found a Captcha implementation I have using a propertyExpression in the 
TML on the src attribute of <IMG> to reference a getImageLink function 
that returns ComponentResources.createActionLink("image",null). Then 
there is an onImage() action handler method that returns a 
StreamResponse. I understand this is ActionLink and not EventLink, but I 
think the concept must be nearly identical.

Alternately, Thiago is suggesting that instead of using 
ComponentResources to generate an ActionLink or EventLink, it may be 
easier to create a seperate Page that handles returning just a 
StreamResponse. In that case the EventLink can be replaced with a 
PageLink and using an activation context the ID for the Image can be 
passed to the Page so it can load the Image, build the StreamResponse, 
and return it.

<30 minutes later> Okay, the PageLink works out, great! I can see the 
biggest issue I was having was setting up the src attribute for IMG 
correctly. I was stuck thinking it was either the URL to the context 
path or the StreamResponse itself, rather than a link to an event or 
page that returns the StreamResponse.

Thanks,
Rich


On 03/11/2011 08:08 AM, Thiago H. de Paula Figueiredo wrote:
> On Fri, 11 Mar 2011 09:24:35 -0300, LLTYK <LL...@mailinator.com> wrote:
>
>> Nobody's mentioned createEventLink. That's where you get the image url,
>> create an event link pointing to the event handler that returns the 
>> stream response.
>
> I haven't mentioned it because my preferred approach is to create a 
> page just for returning StreamResponses. It's more reusable, as it can 
> be used to serve images for any page, while an event must be only used 
> inside a give page.
>


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


Re: Uploading then displaying Images

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Fri, 11 Mar 2011 09:24:35 -0300, LLTYK <LL...@mailinator.com> wrote:

> Nobody's mentioned createEventLink. That's where you get the image url,
> create an event link pointing to the event handler that returns the  
> stream response.

I haven't mentioned it because my preferred approach is to create a page  
just for returning StreamResponses. It's more reusable, as it can be used  
to serve images for any page, while an event must be only used inside a  
give page.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

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


Re: Uploading then displaying Images

Posted by LLTYK <LL...@mailinator.com>.
Nobody's mentioned createEventLink. That's where you get the image url,
create an event link pointing to the event handler that returns the stream
response.

--
View this message in context: http://tapestry-users.832.n2.nabble.com/Uploading-then-displaying-Images-tp6159049p6161239.html
Sent from the Tapestry Users mailing list archive at Nabble.com.

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


Re: Uploading then displaying Images

Posted by Kalle Korhonen <ka...@gmail.com>.
On Thu, Mar 10, 2011 at 5:02 PM, Josh Canfield <jo...@gmail.com> wrote:
>> Sorry, but that's a really bad advice - never put uploaded files under
>> the context path of your application. What happens when you update the
>> WAR?
> Strongly agree.
>>                return new BufferedImageStreamResponse(ImageIO.read(imageStorage.getImageInputStream(imageId)));
> What is the value in using ImageIO instead of just streaming the file bits?

Yeah, that's a bad generic example - in the case I copied it from it's
used to encode various source formats and sizes to a common output
format. But consider whether you want to do it on the fly and pay
recurring costs.

Kalle


> On Thu, Mar 10, 2011 at 4:33 PM, Kalle Korhonen
> <ka...@gmail.com> wrote:
>> On Thu, Mar 10, 2011 at 4:11 PM, Thiago H. de Paula Figueiredo
>> <th...@gmail.com> wrote:
>>> On Thu, 10 Mar 2011 19:24:52 -0300, Rich M <ri...@moremagic.com> wrote:
>>>> Primarily because I can't think of a reasonable way to build a URL to the
>>> I think you have a confusion here. The folder structure you use while
>>> developer doesn't matter, the one in the WAR, exploded or not, does. Servlet
>>> containers normally exploded (unzip) your WAR into a folder. Anything inside
>>> that folder is available. Example: if you have a image.jpg file inside the
>>> root folder of the root context, it's URL is at http://domain/image.jpg
>>> directly. Better yet, most servlet containers (at least Tomcat and Jetty)
>>> support WARs: you don't even create a WAR file, just put the contents of it
>>> inside some configured folder.
>>
>> Sorry, but that's a really bad advice - never put uploaded files under
>> the context path of your application. What happens when you update the
>> WAR?
>>
>> To do it right, you have basically two options, either a) map a
>> virtual path to a physical folder, e.g. /images/ to /var/www/images/
>> or b) open a stream to stream the files from the physical folder. If
>> a) and you are not using anything in front of your servlet container,
>> you'd create another "images" web application (with tomcat, that's a
>> single context file) and for b) it'll perform just as well as the
>> first option if it's the same container serving the bits and you use
>> StreamResponse regardless of whether the bytes come from database or
>> file - it's simple to do, e.g:
>>        public StreamResponse onUploadedImage() throws FileNotFoundException,
>> IOException {
>>                return new BufferedImageStreamResponse(ImageIO.read(imageStorage.getImageInputStream(imageId)));
>>        }
>>
>> Kalle
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

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


Re: Uploading then displaying Images

Posted by Josh Canfield <jo...@gmail.com>.
> Sorry, but that's a really bad advice - never put uploaded files under
> the context path of your application. What happens when you update the
> WAR?

Strongly agree.

>                return new BufferedImageStreamResponse(ImageIO.read(imageStorage.getImageInputStream(imageId)));

What is the value in using ImageIO instead of just streaming the file bits?

Josh

On Thu, Mar 10, 2011 at 4:33 PM, Kalle Korhonen
<ka...@gmail.com> wrote:
> On Thu, Mar 10, 2011 at 4:11 PM, Thiago H. de Paula Figueiredo
> <th...@gmail.com> wrote:
>> On Thu, 10 Mar 2011 19:24:52 -0300, Rich M <ri...@moremagic.com> wrote:
>>> Primarily because I can't think of a reasonable way to build a URL to the
>> I think you have a confusion here. The folder structure you use while
>> developer doesn't matter, the one in the WAR, exploded or not, does. Servlet
>> containers normally exploded (unzip) your WAR into a folder. Anything inside
>> that folder is available. Example: if you have a image.jpg file inside the
>> root folder of the root context, it's URL is at http://domain/image.jpg
>> directly. Better yet, most servlet containers (at least Tomcat and Jetty)
>> support WARs: you don't even create a WAR file, just put the contents of it
>> inside some configured folder.
>
> Sorry, but that's a really bad advice - never put uploaded files under
> the context path of your application. What happens when you update the
> WAR?
>
> To do it right, you have basically two options, either a) map a
> virtual path to a physical folder, e.g. /images/ to /var/www/images/
> or b) open a stream to stream the files from the physical folder. If
> a) and you are not using anything in front of your servlet container,
> you'd create another "images" web application (with tomcat, that's a
> single context file) and for b) it'll perform just as well as the
> first option if it's the same container serving the bits and you use
> StreamResponse regardless of whether the bytes come from database or
> file - it's simple to do, e.g:
>        public StreamResponse onUploadedImage() throws FileNotFoundException,
> IOException {
>                return new BufferedImageStreamResponse(ImageIO.read(imageStorage.getImageInputStream(imageId)));
>        }
>
> Kalle
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

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


Re: Uploading then displaying Images

Posted by Kalle Korhonen <ka...@gmail.com>.
On Thu, Mar 10, 2011 at 4:11 PM, Thiago H. de Paula Figueiredo
<th...@gmail.com> wrote:
> On Thu, 10 Mar 2011 19:24:52 -0300, Rich M <ri...@moremagic.com> wrote:
>> Primarily because I can't think of a reasonable way to build a URL to the
> I think you have a confusion here. The folder structure you use while
> developer doesn't matter, the one in the WAR, exploded or not, does. Servlet
> containers normally exploded (unzip) your WAR into a folder. Anything inside
> that folder is available. Example: if you have a image.jpg file inside the
> root folder of the root context, it's URL is at http://domain/image.jpg
> directly. Better yet, most servlet containers (at least Tomcat and Jetty)
> support WARs: you don't even create a WAR file, just put the contents of it
> inside some configured folder.

Sorry, but that's a really bad advice - never put uploaded files under
the context path of your application. What happens when you update the
WAR?

To do it right, you have basically two options, either a) map a
virtual path to a physical folder, e.g. /images/ to /var/www/images/
or b) open a stream to stream the files from the physical folder. If
a) and you are not using anything in front of your servlet container,
you'd create another "images" web application (with tomcat, that's a
single context file) and for b) it'll perform just as well as the
first option if it's the same container serving the bits and you use
StreamResponse regardless of whether the bytes come from database or
file - it's simple to do, e.g:
	public StreamResponse onUploadedImage() throws FileNotFoundException,
IOException {
		return new BufferedImageStreamResponse(ImageIO.read(imageStorage.getImageInputStream(imageId)));
	}

Kalle

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


Re: Uploading then displaying Images

Posted by ICE Ernesto Arteaga Zavala <ar...@gmail.com>.
:) Thanks!

2012/7/19 Thiago H de Paula Figueiredo <th...@gmail.com>

> On Thu, 19 Jul 2012 11:50:57 -0300, arterzatij <ar...@gmail.com>
> wrote:
>
>  Hi Thiago, how do you get the file from db?
>> I mean the BLOB type of data base to a Java Type?
>>
>
> Yep, probably to a byte array.
>
> --
> Thiago H. de Paula Figueiredo
>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.**apache.org<us...@tapestry.apache.org>
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Saludos,

-------------------------------------------------------------------
"Nada que se consiga sin pena y sin trabajo
 es verdaderamente valioso."
                                          Joseph Addison
-------------------------------------------------------------------

ICE Ernesto Arteaga Zavala
Ingeniero de Desarrollo

Re: Uploading then displaying Images

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Thu, 19 Jul 2012 11:50:57 -0300, arterzatij <ar...@gmail.com>  
wrote:

> Hi Thiago, how do you get the file from db?
> I mean the BLOB type of data base to a Java Type?

Yep, probably to a byte array.

-- 
Thiago H. de Paula Figueiredo

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


Re: Uploading then displaying Images

Posted by arterzatij <ar...@gmail.com>.
Hi Thiago, how do you get the file from db?

I mean the BLOB type of data base to a Java Type?


Thanks in advance!

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Uploading-then-displaying-Images-tp3423946p5714604.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Uploading then displaying Images

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Thu, 10 Mar 2011 19:24:52 -0300, Rich M <ri...@moremagic.com> wrote:

> Primarily because I can't think of a reasonable way to build a URL to  
> the file that could actually be served. I wish I was more knowledgeable  
> about servlets and such, but if my application is running from a WAR,  
> how would I get any files into that context? In development I use maven  
> directory structure and the mvn jetty:run command to execute. From here  
> I know I can place files relatively from my context in  
> src/main/webapp/<where-ever> and serve it as an Asset. However, when I  
> have to deploy it into production and run it as a WAR in stand-alone  
> Jetty, I think this approach is no longer viable.

I think you have a confusion here. The folder structure you use while  
developer doesn't matter, the one in the WAR, exploded or not, does.  
Servlet containers normally exploded (unzip) your WAR into a folder.  
Anything inside that folder is available. Example: if you have a image.jpg  
file inside the root folder of the root context, it's URL is at  
http://domain/image.jpg directly. Better yet, most servlet containers (at  
least Tomcat and Jetty) support WARs: you don't even create a WAR file,  
just put the contents of it inside some configured folder.

In other words: if you upload your files to the root folder of your  
application in the server, they're in the context and can be reached by  
users.

You'd use a StreamResponse if you stored your files in a database instead  
of the file system.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

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


Re: Uploading then displaying Images

Posted by Josh Canfield <jo...@gmail.com>.
I think this thread has gotten me very confused.

You have uploaded files, presumably you know where they are and can
identify them. You want to get those files to display in your browser.
In order to do that you create an <img src=""/> tag that contains a
URL as the value of the src attribute that points to your server that
can serve the file.

That endpoint can be a Tapestry page that accepts enough information
to find identify your file and return a StreamResponse to send the
data back for that image request.

It seems like you are thinking you need to craft a URL that actually
points to the file in the filesystem, but that's not the case.

Josh

On Thu, Mar 10, 2011 at 2:24 PM, Rich M <ri...@moremagic.com> wrote:
> On 03/10/2011 04:21 PM, Thiago H. de Paula Figueiredo wrote:
>>
>> On Thu, 10 Mar 2011 17:49:14 -0300, Rich M <ri...@moremagic.com> wrote:
>>
>>> Okay, that makes sense. Is there a way to use the StreamResponse instead
>>> of the URL then to display an image in the browser?
>>
>> Unless you want to generate one of that data URLs
>> (http://en.wikipedia.org/wiki/Data_URI_scheme), you'll need to generate an
>> URL for it just like it was described in the thread you linked.
>> StreamResponses don't have URLs by themselves.
>>
>>> My application will be able to more reliably serve the images via the
>>> StreamResponse rather than the URL
>>
>> Why?
>
> Primarily because I can't think of a reasonable way to build a URL to the
> file that could actually be served. I wish I was more knowledgeable about
> servlets and such, but if my application is running from a WAR, how would I
> get any files into that context? In development I use maven directory
> structure and the mvn jetty:run command to execute. From here I know I can
> place files relatively from my context in src/main/webapp/<where-ever> and
> serve it as an Asset. However, when I have to deploy it into production and
> run it as a WAR in stand-alone Jetty, I think this approach is no longer
> viable.
>>
>>> so I'd like to consider that approach, or at least know if how to do it
>>> for curiosity sake.
>>
>> Wise words. :)
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

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


Re: Uploading then displaying Images

Posted by Rich M <ri...@moremagic.com>.
On 03/10/2011 04:21 PM, Thiago H. de Paula Figueiredo wrote:
> On Thu, 10 Mar 2011 17:49:14 -0300, Rich M <ri...@moremagic.com> wrote:
>
>> Okay, that makes sense. Is there a way to use the StreamResponse 
>> instead of the URL then to display an image in the browser?
>
> Unless you want to generate one of that data URLs 
> (http://en.wikipedia.org/wiki/Data_URI_scheme), you'll need to 
> generate an URL for it just like it was described in the thread you 
> linked. StreamResponses don't have URLs by themselves.
>
>> My application will be able to more reliably serve the images via the 
>> StreamResponse rather than the URL
>
> Why?
Primarily because I can't think of a reasonable way to build a URL to 
the file that could actually be served. I wish I was more knowledgeable 
about servlets and such, but if my application is running from a WAR, 
how would I get any files into that context? In development I use maven 
directory structure and the mvn jetty:run command to execute. From here 
I know I can place files relatively from my context in 
src/main/webapp/<where-ever> and serve it as an Asset. However, when I 
have to deploy it into production and run it as a WAR in stand-alone 
Jetty, I think this approach is no longer viable.
>
>> so I'd like to consider that approach, or at least know if how to do 
>> it for curiosity sake.
>
> Wise words. :)
>


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


Re: Uploading then displaying Images

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Thu, 10 Mar 2011 17:49:14 -0300, Rich M <ri...@moremagic.com> wrote:

> Okay, that makes sense. Is there a way to use the StreamResponse instead  
> of the URL then to display an image in the browser?

Unless you want to generate one of that data URLs  
(http://en.wikipedia.org/wiki/Data_URI_scheme), you'll need to generate an  
URL for it just like it was described in the thread you linked.  
StreamResponses don't have URLs by themselves.

> My application will be able to more reliably serve the images via the  
> StreamResponse rather than the URL

Why?

> so I'd like to consider that approach, or at least know if how to do it  
> for curiosity sake.

Wise words. :)

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

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


Re: Uploading then displaying Images

Posted by Rich M <ri...@moremagic.com>.
On 03/10/2011 03:17 PM, Thiago H. de Paula Figueiredo wrote:
> On Thu, 10 Mar 2011 16:37:29 -0300, Rich M <ri...@moremagic.com> wrote:
>
>> Hi,
>
> Hi!
>
>> I had read this thread 
>> http://tapestry.1045711.n5.nabble.com/How-to-display-Blob-byte-array-image-td2436148.html 
>> along with other information regarding uploading/displaying images. I 
>> think I'm a bit confused as to what my ImageStreamResponse is or 
>> should be achieving. I had thought using that I might be able to 
>> display the image itself in the TML, but it seems I'd need the URL 
>> instead. If I had the URL in any case then what purpose does the 
>> ImageStreamResponse serve?
>
> None. When you have the image in some public URL, inside or outside 
> your application, you don't need a StreamResponse for it. Just use its 
> URL. StreamResponse is used when you have the content generated on the 
> fly, available as an InputStream or in memory.
>
Okay, that makes sense. Is there a way to use the StreamResponse instead 
of the URL then to display an image in the browser? My application will 
be able to more reliably serve the images via the StreamResponse rather 
than the URL so I'd like to consider that approach, or at least know if 
how to do it for curiosity sake.

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


Re: Uploading then displaying Images

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Thu, 10 Mar 2011 16:37:29 -0300, Rich M <ri...@moremagic.com> wrote:

> Hi,

Hi!

> I had read this thread  
> http://tapestry.1045711.n5.nabble.com/How-to-display-Blob-byte-array-image-td2436148.html  
> along with other information regarding uploading/displaying images. I  
> think I'm a bit confused as to what my ImageStreamResponse is or should  
> be achieving. I had thought using that I might be able to display the  
> image itself in the TML, but it seems I'd need the URL instead. If I had  
> the URL in any case then what purpose does the ImageStreamResponse serve?

None. When you have the image in some public URL, inside or outside your  
application, you don't need a StreamResponse for it. Just use its URL.  
StreamResponse is used when you have the content generated on the fly,  
available as an InputStream or in memory.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

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