FileUploadEvent
을 통해 업로드 된 파일 콘텐츠를 가져올 수 있습니다. Apache Commons FileUpload를 사용하는 PrimeFaces 4.x 또는 컨텍스트 매개 변수 primefaces.UPLOADER
을 PrimeFaces 5.x에서 commons
으로 설정하면 UploadedFile#getContents()
을 사용하여 업로드 된 파일을 byte[]
으로 가져올 수 있습니다. 즉 not implemented in NativeUploadedFile
implementation있어 같이 컨텍스트 PARAM primefaces.UPLOADER
없거나 JSF 2.2 사용시 auto
또는 native
로 설정된 PrimeFaces 5.x의에서는
public void handleFileUpload(FileUploadEvent event) {
byte[] content = event.getFile().getContents();
// ...
}
다음 getContents()
는 null
를 리턴한다. 대신 UploadedFile#getInputStream()
을 사용하고 read bytes from it, e.g. with help of commons IO을 사용하십시오.
public void handleFileUpload(FileUploadEvent event) {
byte[] content = IOUtils.toByteArray(event.getFile().getInputstream());
// ...
}
은 마지막으로, 당신의 기업에서이 byte[]
을 설정/유지를 병합합니다.
양식 인코딩 유형을 multipart/form-data
으로 설정하고 Apache Commons FileUpload를 사용할 때 file upload filter을 web.xml
으로 PrimeFaces 사용자 가이드별로 구성했는지 확인하십시오.
오류가 발생했습니다 : javax.validation.ConstraintViolationException : 콜 검증 이벤트 : 'prePersist'에서 자동 Bean 유효성 검사를 실행하는 동안 Bean 유효성 검증 제약 조건이 위반되었습니다. 자세한 내용은 포함 된 제약 조건을 참조하십시오. –
fileUpload 구성 요소에서받은 StreamedContent로 재생해야합니다. 쇼케이스에 예제가 있습니다. 어떤 버전의 PF를 사용합니까? streamedContent가 있으면 DB에 삽입 할 수 있습니다. – spauny