In the following code, I made ImageInlineStreamResponse by extending
InlineStreamResponse from
http://wiki.apache.org/tapestry/Tapestry5HowToStreamAnExistingBinaryFile.
public ImageInlineStreamResponse getPictureAsImageStream(Integer
someId) throws FileNotFoundException {
File file = toFileUsingMySecretPathAlgorithm(someId);
return new ImageInlineStreamResponse(file);
}
ImageInlineStreamResponse calls super(file), then sets the contentType
appropriately, eg. this.contentType = "image/jpeg".
Two modifications to InlineStreamResponse :
- add this constructor:
public InlineStreamResponse(File file) throws FileNotFoundException {
this.is = new FileInputStream(file);
this.filename = file.getName();
}
- in prepareResponse(...), add this:
// Set content length to prevent chunking - see
//
http://tapestry-users.832.n2.nabble.com/Disable-Transfer-Encoding-chunked-from-StreamResponse-td5269662.html#a5269662
try {
response.setHeader("Content-Length", "" +
is.available());
}
catch (IOException e) {
// Aaaaaaarrrrrrrrrggggggggggghhhhhhhhh! Unrecoverable?
Client will simply fail to receive the file.
e.printStackTrace();
}
HTH,
Geoff
On 25 Feb 2015, at 11:58 am, Thiago H de Paula Figueiredo <thiag...@gmail.com>
wrote:
> On Tue, 24 Feb 2015 20:29:44 -0300, Balázs Palcsó <palcso.bal...@gmail.com>
> wrote:
>
>> Hi,
>
> Hi!
>
>> I am developing an application that allows uploading images with tapestry
>> 5.4-beta-28.
>>
>> My plan is to store the uploaded files on the file system. I have managed
>> to implement this bit, but I am struggling to come up with a solution to
>> show the uploaded images.
>
> I prefer some kind of database, as storing files in the filesystem can be a
> pain and serving them can be a serious security risk, but that's not the
> point of this message. :)
>
>> I am getting an error if I include ChenilleKit Tapestry in the classpath
>> Service id 'KaptchaProducer' has already been defined by
>> org.chenillekit.image.ChenilleKitImageModule.buildKaptchaProducer(Map)
>
> This means there's two ChenilleKit JARs in the classpath. Or two different
> module classes defining a service with the same id, but you've cut off the
> error message, so it's not possible to know.
>
> --
> Thiago H. de Paula Figueiredo
> Tapestry, Java and Hibernate consultant and developer
> http://machina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>