0

I want to mock the functionality that we have in chrome, where one can get a dialog box to save a document.

It will be helpful, if I can obtain a window similar to chrome where you can select directory.

I found this input:

<input type="file" webkitdirectory="webkitdirectory" directory="directory" multiple="multiple"/>

and I use java, spring mvc and html. Any help how to go about it.

enter image description here

or

enter image description here

Mureinik
  • 297,002
  • 52
  • 306
  • 350
Pablo Grela
  • 29
  • 1
  • 4
  • What do you mean by a *Save As* button? Just let the browser handles this, not you. Otherwise, please provide an image of what you're looking for. Since you don't have enough rep to post images, provide the link to the image. – Luiggi Mendoza May 04 '15 at 16:07
  • check this http://stackoverflow.com/questions/2809688/directory-chooser-in-html-page –  May 04 '15 at 16:22
  • To clarify you are trying to download something from your website and you want it to come up with a dialogue box with option to Save As? – Aeseir May 05 '15 at 00:55
  • Yes, i implemeted a method createpdf, i want that user select the name and place where save it. I also worth me a button to select a path where save the document. – Pablo Grela May 05 '15 at 07:56
  • This post: http://stackoverflow.com/questions/15201071/how-to-get-full-path-of-selected-file-on-change-of-input-type-file-using-jav, it does not solve because it is not working. – Pablo Grela May 11 '15 at 10:47

1 Answers1

0

I has solucionated my problem:

viewPDF:

   public static ResponseEntity<byte[]> viewPdf(String path, String file) {
      Path path2 = Paths.get(path);
      byte[] contents = null;
      try {
         contents = Files.readAllBytes(path2);
      } catch (IOException e) {
         e.getMessage();
      }

      HttpHeaders headers = new HttpHeaders();
      headers.setContentType(MediaType.parseMediaType("application/pdf"));
      headers.setCacheControl("must-revalidate, post-check=0, pre-check=0");
      // Download PDF
      // headers.setContentDispositionFormData(pathForm.getFile(),
      // pathForm.getFile());
      // View PDF
      headers.add("content-disposition", "inline;filename=" + file);
      ResponseEntity<byte[]> response = new ResponseEntity<byte[]>(contents, headers, HttpStatus.OK);
      return response;
   }

Post:

   @RequestMapping(value = "feeMemberList/payMemberList", method = RequestMethod.POST, params = { "createPdf" })
   public ResponseEntity<byte[]> createPdf(@Valid @ModelAttribute PathForm pathForm,
         Errors errors, @RequestParam("createPdf") String createPdf, RedirectAttributes ra,
         Model model) {

      String title;
      String path = pathForm.getPath() + "/" + pathForm.getFile() + ".pdf";


      createPdfFeeMember(messageSource, feeMember.getId(), path, title, createPdf);
      return CreatePdf.viewPdf(path, pathForm.getFile());
   }

In this way the pdf and keep you open. The user will appear where you want to save.

Pablo Grela
  • 29
  • 1
  • 4