Home » RESTful JAX-RS File Download Example

RESTful JAX-RS File Download Example

by Online Tutorials Library

RESTful JAX-RS File Download Example

We can download text files, image files, pdf files, excel files in java by JAX-RS API. To do so we need to write few lines of code only. Here, we are using jersey implementation for developing JAX-RS file download examples.

You need to specify different content type to download different files. The @Produces annotation is used to specify the type of file content.

  1. @Produces(“text/plain”): for downloading text file.
  2. @Produces(“image/png”): for downloading png image file.
  3. @Produces(“application/pdf”): for downloading PDF file.
  4. @Produces(“application/vnd.ms-excel”): for downloading excel file.
  5. @Produces(“application/msword”): for downloading ms word file.

Click me to download jersey jar files.


JAX-RS Text File Download

File: FileDownloadService.java

File: web.xml

File: index.html

Now run this application on server, you will see the following output:

Output:

jax rs file download text example
Click me to download this example


JAX-RS Image File Download

File: FileDownloadService.java

File: web.xml

Same as above example.

File: index.html

Click me to download this example


JAX-RS PDF File Download

File: FileDownloadService.java

File: web.xml

Same as above example.

File: index.html

Click me to download this example

You may also like