Chunked mode uploads files in (small) chunks to allow resume-functionality.
<div class="card">
<h:form>
<p:fileUpload listener="#{fileUploadView.handleFileUpload}" mode="advanced" dragDropSupport="false"
multiple="true" update="messages" maxChunkSize="1000000">
<p:validateFile sizeLimit="10000000" fileLimit="3" allowTypes="/(\.|\/)(gif|jpeg|jpg|png)$/" />
</p:fileUpload>
<p:growl id="messages" showDetail="true" keepAlive="true"/>
</h:form>
</div>
@Named
@RequestScoped
public class FileUploadView {
private UploadedFile file;
private UploadedFiles files;
private String dropZoneText = "Drop zone p:inputTextarea demo.";
public void upload() {
if (file != null) {
FacesMessage message = new FacesMessage("Successful", file.getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, message);
}
}
public void uploadMultiple() {
if (files != null) {
for (UploadedFile f : files.getFiles()) {
FacesMessage message = new FacesMessage("Successful", f.getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, message);
}
}
}
public void handleFileUpload(FileUploadEvent event) {
FacesMessage message = new FacesMessage("Successful", event.getFile().getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, message);
}
public void handleFileUploadTextarea(FileUploadEvent event) {
String jsVal = "PF('textarea').jq.val";
String fileName = EscapeUtils.forJavaScript(event.getFile().getFileName());
PrimeFaces.current().executeScript(jsVal + "(" + jsVal + "() + '\\n\\n" + fileName + " uploaded.')");
}
public void handleFilesUpload(FilesUploadEvent event) {
for (UploadedFile f : event.getFiles().getFiles()) {
FacesMessage message = new FacesMessage("Successful", f.getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, message);
}
}
public UploadedFile getFile() {
return file;
}
public void setFile(UploadedFile file) {
this.file = file;
}
public UploadedFiles getFiles() {
return files;
}
public void setFiles(UploadedFiles files) {
this.files = files;
}
public String getDropZoneText() {
return dropZoneText;
}
public void setDropZoneText(String dropZoneText) {
this.dropZoneText = dropZoneText;
}
}