users@jersey.java.net

Re: [Jersey] File Download

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 22 Mar 2010 13:02:12 +0100

On Mar 22, 2010, at 12:41 PM, emile wrote:

>
> Hi,
>
> I have a method in my resource which is responsible for providing
> the file
> content. Using the following code i was able to get the content on my
> browser -
>
> return Response.ok(file,"text/plain").header("Content-Type",
> "application/pdf").build();
>

The above should be:

   return Response.ok(file,"application/pdf").build();

the header method call is redundant as the second parameter of the ok
method sets the content-type header.

You can verify what Jersey sends by logging the response:

   https://jersey.dev.java.net/nonav/apidocs/latest/jersey/com/sun/jersey/api/container/filter/LoggingFilter.html


> But I'm unsure how to get the file content in its corresponding
> application.
> For e.g. pdf file content should be displayed using the Acrobat
> reader.
>


That might also depend on how tour browser is set up to process
content of application/pdf.

I presume most browsers are set up to support this out of the box.

Paul.