Hi Arie,

I don't know your usecase, but what I usually do when I need to stream data through wicket, I use a ResourceStreamRequestTarget along with an implementation of AbstractResourceStreamWriter. In your AbstractResourceStreamWriter you can onverride de getContentType() method as :

@Override
public String getContentType() {
        return "image/png";
}

and when you want to stream your content, just do :
RequestCycle().get().setRequestTarget(
        new ResourceStreamRequestTarget(new MyResourceStreamWriterImpl());

Hope this helps !

Happy new year ;)

Antoine.

Arie Fishler wrote:
Hi,

I am trying to stream an image to the response and setting the proper mime
type to it prior to writing the stream to the output.

The file exists and is written but the mime type of the response is not set
according to what I expect it to be ("image/png"). Any idea?


WebResponse response = (WebResponse)getRequestCycle().getResponse();

*if* (imagePath != *null*) {

*try* {

File imageFile = *new* File(imagePath);

FileInputStream inputStream = *new* FileInputStream(imageFile);

response.setContentType(*DEFAULT_MIME_TYPE*);

Streams.*copy*(inputStream, response.getOutputStream());

*return*;

}

*catch* (FileNotFoundException e) {

}

*catch* (IOException e) {

}

}

// 404

response.getHttpServletResponse().setStatus(*NOT_FOUND*);


--
Antoine Angénieux
Associé

Clinigrid
5, avenue Mozart
75016 Paris, France
+336 60 21 09 18
aangeni...@clinigrid.com



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to