You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by "Angelo C." <an...@gmail.com> on 2012/08/23 16:04:07 UTC

StreamResponse for small cacheable images

Hi,

I have some very small jpegs that are kept in the file system, what is the
right method to render them to client and it can also be cached in the
browser? I'm looking at StreamResponse, is it the right way to go? Thanks,

Angelo



--
View this message in context: http://tapestry.1045711.n5.nabble.com/StreamResponse-for-small-cacheable-images-tp5715755.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: StreamResponse for small cacheable images

Posted by "Angelo C." <an...@gmail.com>.
it's not static, but some small photos that are kept just for a short time.



--
View this message in context: http://tapestry.1045711.n5.nabble.com/StreamResponse-for-small-cacheable-images-tp5715755p5715762.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: StreamResponse for small cacheable images

Posted by Lance Java <la...@googlemail.com>.
If the images are static and you can build them into the jar or war, I'd
avoid using StreamResponse and instead use the "asset:" or "context:"
binding prefixes.

For jpegs on the classpath
${asset:path/to/image.jpg} 

For jpegs in the web context
${context:path/to/image.jpg 

http://tapestry.apache.org/assets.html



--
View this message in context: http://tapestry.1045711.n5.nabble.com/StreamResponse-for-small-cacheable-images-tp5715755p5715761.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: StreamResponse for small cacheable images

Posted by Lance Java <la...@googlemail.com>.
Use a separate page to generate the images and generate Links to the page.
For the page, onActivate(String image) returns the StreamResponse.



--
View this message in context: http://tapestry.1045711.n5.nabble.com/StreamResponse-for-small-cacheable-images-tp5715755p5715782.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: StreamResponse for small cacheable images

Posted by "Angelo C." <an...@gmail.com>.
that works, thanks.

the component approach generates different urls for the same photo depending
on which page the component is used, maybe some other approach that can
create a unique url regardless pages?

http://localhost:8080/test123.memimg:image/image1
http://localhost:8080/testxyz.memimg:image/image1




--
View this message in context: http://tapestry.1045711.n5.nabble.com/StreamResponse-for-small-cacheable-images-tp5715755p5715775.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: StreamResponse for small cacheable images

Posted by Lance Java <la...@googlemail.com>.
If you want the image name as a parameter

        Link getImage(String imageName) { 
                return resources.createEventLink("Image", imageName); 
        }

        private StreamResponse onImage(String imageName) { 
                return new ImageResponse(imageName); 
        }

If you want to cache the image, you will need to set the appropriate
response headers in ImageResponse.prepareResponse(Response)



--
View this message in context: http://tapestry.1045711.n5.nabble.com/StreamResponse-for-small-cacheable-images-tp5715755p5715766.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: StreamResponse for small cacheable images

Posted by "Angelo C." <an...@gmail.com>.
here is the code I'm trying to come out, ImageResponse derived from
StreamResponse, the issue now is, the img url is always the same for every
photo:

http://localhost:8080/test123.memimg:image

tml:

< img t:type="MemImg" image_name='literal:image1' / >

java:
@SupportsInformalParameters
public class MemImg {

	@Inject
	private ComponentResources resources;

	@Inject
	private Response response;


	@Parameter(required = true)
	private String image_name;

	boolean beginRender(MarkupWriter writer) {
		writer.element("img", "src", getImage());
		resources.renderInformalParameters(writer);
		writer.end();
		return false;
	}

	Link getImage() {
		return resources.createEventLink("Image");
	}

	private StreamResponse onImage() {
		return new ImageResponse(image_name);
	}
}



--
View this message in context: http://tapestry.1045711.n5.nabble.com/StreamResponse-for-small-cacheable-images-tp5715755p5715763.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: StreamResponse for small cacheable images

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Thu, 23 Aug 2012 11:04:07 -0300, Angelo C. <an...@gmail.com>  
wrote:

> Hi,

Hi!

> I have some very small jpegs that are kept in the file system, what is  
> the right method to render them to client and it can also be cached in  
> the
> browser? I'm looking at StreamResponse, is it the right way to go?

Yes.

-- 
Thiago H. de Paula Figueiredo

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