You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Arie Fishler <ar...@gmail.com> on 2008/12/31 10:05:16 UTC

Modifying the mimetype of the response

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*);

Re: Modifying the mimetype of the response

Posted by Arie Fishler <ar...@gmail.com>.
ok

On Wed, Dec 31, 2008 at 11:35 AM, Martijn Dashorst <
martijn.dashorst@gmail.com> wrote:

> Please createca Jira issue.
>
> Martijn
>
> On 12/31/08, Arie Fishler <ar...@gmail.com> 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*);
> >
>
>
> --
> Become a Wicket expert, learn from the best: http://wicketinaction.com
> Apache Wicket 1.3.4 is released
> Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Modifying the mimetype of the response

Posted by Martijn Dashorst <ma...@gmail.com>.
Please createca Jira issue.

Martijn

On 12/31/08, Arie Fishler <ar...@gmail.com> 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*);
>


-- 
Become a Wicket expert, learn from the best: http://wicketinaction.com
Apache Wicket 1.3.4 is released
Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.

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


Re: Modifying the mimetype of the response

Posted by Arie Fishler <ar...@gmail.com>.
Well Antoine...this is truly a sign of a new good year since your little
trick just works very well.

Much appreciated here!!!

Cheers, happy new year,
Arie.

On Wed, Dec 31, 2008 at 6:46 PM, Arie Fishler <ar...@gmail.com> wrote:

>  Will try that and report.
>
> Thanks for the suggestion.
>
> Cheers,
> Arie
>
>   On Wed, Dec 31, 2008 at 4:09 PM, Antoine Angenieux <
> aangenieux@clinigrid.com> wrote:
>
>> 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
>> aangenieux@clinigrid.com
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>

Re: Modifying the mimetype of the response

Posted by Arie Fishler <ar...@gmail.com>.
Will try that and report.

Thanks for the suggestion.

Cheers,
Arie

On Wed, Dec 31, 2008 at 4:09 PM, Antoine Angenieux <aangenieux@clinigrid.com
> wrote:

> 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
> aangenieux@clinigrid.com
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Modifying the mimetype of the response

Posted by Antoine Angenieux <aa...@clinigrid.com>.
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
aangenieux@clinigrid.com



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