How To Download A File Inwards Lather Api

First nosotros define the interface similar this:
 @WebMethod ActionStatus downloadFile(@WebParam(name = "file") String file); 

Implementation:
 populace ActionStatus downloadFile(String filePath) {  MessageContext mc = webServiceContext.getMessageContext(); // encounter https://ngeblognow.blogspot.com//search?q=how-to-access-httpservletrequest-and  HttpServletResponse answer = (HttpServletResponse) mc.get(MessageContext.SERVLET_RESPONSE);    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();  } pick out get got of (IOException e) {   // grip exception  } } 

*Note: IOUtils is from apache commons.
Next
Previous
Click here for Comments

0 komentar:

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