public RemoteFile open(String path, Set<OpenMode> modes, FileAttributes fa) throws IOException { final byte[] handle = doRequest( newRequest(PacketType.OPEN).putString(path, sub.getRemoteCharset()).putUInt32(OpenMode.toMask(modes)).putFileAttributes(fa) ).ensurePacketTypeIs(PacketType.HANDLE).readBytes(); return new RemoteFile(this, path, handle); }
@ResponseBody @RequestMapping(value = "get/pdf/{id}", headers="Accept=*/*", method = RequestMethod.GET) public ResponseEntity<InputStreamResource> getPdfContractById(@PathVariable("id") Long id){ // Get the remove file based on the fileaddress RemoteFile remotefile = new RemoteFile(id); // Set the input stream InputStream inputstream = remotefile.getInputStream(); // asume that it was a PDF file HttpHeaders responseHeaders = new HttpHeaders(); InputStreamResource inputStreamResource = new InputStreamResource(inputStream); responseHeaders.setContentLength(contentLengthOfStream); responseHeaders.setContentType(MediaType.valueOf("application/pdf")); return new ResponseEntity<InputStreamResource> (inputStreamResource, responseHeaders, HttpStatus.OK); }
@ResponseBody @RequestMapping(value = "/download/{fileaddress}", method = RequestMethod.GET) public Object download(@PathVariable(value = "fileaddress") String fileaddress, RedirectAttributes redirectAttrs) throws Exception { if(StringUtils.hasText(fileaddress)){ try{ // Get the remove file based on the fileaddress RemoteFile remotefile = new RemoteFile(fileaddress); // Set the input stream InputStream inputstream = remotefile.getInputStream(); // asume that it was a PDF file HttpHeaders responseHeaders = new HttpHeaders(); InputStreamResource inputStreamResource = new InputStreamResource(inputStream); responseHeaders.setContentLength(contentLengthOfStream); responseHeaders.setContentType(MediaType.valueOf("application/pdf")); return new ResponseEntity<InputStreamResource> inputStreamResource, responseHeaders, HttpStatus.OK); } catch (MyExceptionA | MyExceptionB | MyExceptionC | MyExceptionD ex) { redirectAttrs.addFlashAttribute("error", ex.getMessage()); } } else { redirectAttrs.addFlashAttribute("error", "File name is required"); } return "redirect:/addresses"; }
public RemoteFile open(String path, Set<OpenMode> modes, FileAttributes fa) throws IOException { final String handle = doRequest( newRequest(PacketType.OPEN).putString(path).putUInt32(OpenMode.toMask(modes)).putFileAttributes(fa) ).ensurePacketTypeIs(PacketType.HANDLE).readString(); return new RemoteFile(this, path, handle); }
public RemoteFile open(String path, Set<OpenMode> modes, FileAttributes fa) throws IOException { final byte[] handle = doRequest( newRequest(PacketType.OPEN).putString(path, sub.getRemoteCharset()).putUInt32(OpenMode.toMask(modes)).putFileAttributes(fa) ).ensurePacketTypeIs(PacketType.HANDLE).readBytes(); return new RemoteFile(this, path, handle); }