Para implementar este ejemplo primero debemos de descargar los jar tal como se muestra en la IMG.
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>
org.primefaces.webapp.filter.FileUploadFilter
</filter-class>
<init-param>
<param-name>thresholdSize</param-name>
<param-value>51200</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
En managedBean ingresamos el siguiente codigo
private UploadedFile uploadedFile;
creamos el get y set
public void uploadPhoto(FileUploadEvent e) throws IOException {
uploadedFile = e.getFile();
ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
String filePath = ec.getRealPath(String.format("/resources/img/%s", uploadedFile.getFileName()));
if (null != uploadedFile) {
FileOutputStream fos = new FileOutputStream(filePath);
fos.write(uploadedFile.getContents());
fos.flush();
fos.close();
}
FacesContext.getCurrentInstance().addMessage("messages", new FacesMessage(FacesMessage.SEVERITY_INFO, "subio elvideo con exito " + uploadedFile.getFileName(), ""));
}
pruebas
tambien te puede interesar





No hay comentarios:
Publicar un comentario