How To Download A File Using Remainder Api

Normally I practise an interface when defining a REST api, this is useful when testing using Arquillian. To define a download file api nosotros must define the method below inwards the interface.
 @GET @Path("/downloadFile") ActionStatus downloadFile(@QueryParam("file") String file); 

And as well as thence inwards the implementation nosotros have:
 populace void downloadFile(String filePath) throws BusinessApiException {  HttpServletResponse reply = // encounter https://ngeblognow.blogspot.com//search?q=how-to-access-httpservletrequest-and    File file = novel File(getProviderRootDir() + File.separator + filePath);  if (!file.exists()) {   // grip exception  }   campaign {   FileInputStream fis = novel FileInputStream(file);   response.setContentType(Files.probeContentType(file.toPath()));   response.setContentLength((int) file.length());   response.addHeader("Content-disposition", "attachment;filename=\"" + file.getName() + "\"");   IOUtils.copy(fis, response.getOutputStream());   response.flushBuffer();  } select direct maintain of (IOException e) {   // grip exception  } } 

*Note: IOUtils is from apache commons.

Related Post:

Next
Previous
Click here for Comments

0 komentar:

Please comment if there are any that need to be asked.

:)
:(
hihi
:-)
:D
=D
:-d
;(
;-(
@-)
:P
:o
:>)
(o)
[-(
:-?
(p)
:-s
(m)
8-)
:-t
:-b
b-(
:-#
=p~
$-)
(y)
(f)
x-)
(k)
(h)
(c)
cheer