2016-10-24 3 views
0

사용자 정의 파일을 primeface로 다운로드하고 싶습니다. 필자는 "파일 다운로드"를위한 프리덤 쇼케이스에서 설명한대로 특정 파일에 대해 그렇게 할 수있었습니다. 하지만 실제로 원하는 것은 "다운로드 버튼"을 누르면 파일 대화 상자가 열리므로 사용자가 다운로드 할 파일을 선택할 수 있습니다. 그게 가능하니?사용자가 선택한 파일을 다운로드하거나 사용자가 선택한 디렉토리에 파일을 업로드합니다.

과 같은 특정 파일 다운로드 lokks에 대한 나의 현재 코드 : 사용자가 자신을 위해 파일을 업로드 할 폴더를 선택할 수 있도록

public void handleLanguageFileDownload() throws FileNotFoundException, IOException { 

     FacesContext fc = FacesContext.getCurrentInstance(); 
     ExternalContext ec = fc.getExternalContext(); 

     File fileToDownload = new File(DataManager.configreader.getLang_source()); 
     String fileName = fileToDownload.getName(); 
     String contentType = ec.getMimeType(fileName); 
     int contentLength = (int) fileToDownload.length(); 

     ec.responseReset(); 
     ec.setResponseContentType(contentType); 
     ec.setResponseContentLength(contentLength); 
     ec.setResponseHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\""); 

     OutputStream output = ec.getResponseOutputStream(); 

     Files.copy(fileToDownload.toPath(), output); 

     fc.responseComplete(); 
} 

나는, 파일 업로드에 대한 정확한 동일한 동작을합니다. 현재 구현은 파일을 특정 폴더에만 업로드합니다. 특정 폴더에 파일을 업로드

나의 현재 코드는 다음과 같습니다

public void handleLanguageFileUpload(FileUploadEvent event) throws IOException { 

     if (!this.role.canManageLanguage){ 
      return; 
     } 

     String [] filePathParts =  DataManager.configreader.getLang_source().split("/"); 
     String uploadPathString = DataManager.configreader.getLang_source().replaceAll(filePathParts[filePathParts.length - 1],""); //event.getFile().getFileName() 
     File uploadPath = new File(uploadPathString); 
     File fileToUpload = new File(uploadPath, event.getFile().getFileName()); 

     try (InputStream input = event.getFile().getInputstream()) { 
      if(event.getFile().getFileName().equals(filePathParts[filePathParts.length - 1])) { //fileToUpload.getName() 
      Files.copy(input, fileToUpload.toPath(), StandardCopyOption.REPLACE_EXISTING); 
      uiManager.userMessage.info (event.getFile().getFileName() + " " + this.translate("msg_has_been_uploaded") + " !"); 
      this.getOwnTreeVersion(); 
      } 
      else { 
       uiManager.userMessage.error (event.getFile().getFileName() + " " + this.translate("msg_is_wrong_cannot_be_uploaded") +": " + filePathParts[filePathParts.length - 1] + " !"); 
      } 
     } 
    } 

당신의 도움에 미리 감사드립니다! 파일 선택 작업

+0

나는 사용자가 파일을 선택할 수있는 기회를 주었다. –

+0

예, 정확하게하고 싶습니다! 네가 나를 도울 수 있다면 아주 좋을거야! 감사!!! – shaolinmonkabbot

+0

그것은 매우 복잡한 해결책이고 stackoverflow가 당신에게 그것을 해줄 방법을 설명하려고 노력할 해결책을 제공하지 않는다는 것을 이해합니다. –

답변

-1

프로젝트 Upload File Step by Step에서 그것을 구현하는 방법을 이해하려면이 게시물 업로드 방법 표정으로 만 가능하며 당신이 FileSizeLimite 많은을 추가해야하는 경우도 Primefaces 웹 사이트 Primefaces Upload File에서 자세한 내용을보실 수 있습니다 다른 기능들.

지금 다운로드 방법에 대해 난 당신이 수동으로 설정할 수 있습니다 Primefaces Download File Primefaces 웹 사이트에 대한 자세한 내용을 읽을 수 있지만, 동적되지 않습니다 (일반적으로는 다운로드의) 당신은 기본 파일 위치를 가지고 있기 때문에 불가능하다고 말했 이 게시물 Change Download Path을보십시오.

+0

나는 다른 단계를 바로 잡고있다 –

+0

이것을 보았 느냐?!? –

+0

안녕하세요, 예 저는 방금 본 것을 보았고 응답 해 주셔서 대단히 감사합니다. 그러나 이것은 내가 필요한 것에 너무 많이 있습니다. – shaolinmonkabbot

관련 문제