示例#1
0
 public void listener(UploadEvent event) throws Exception {
   UploadItem item = event.getUploadItem();
   File file = new File();
   file.setLength(item.getData().length);
   file.setName(item.getFileName());
   file.setData(item.getData());
   files.add(file);
   uploadsAvailable--;
 }
示例#2
0
  public void uploadImage(UploadEvent evento) throws FileNotFoundException {
    FacesContext fc = FacesContext.getCurrentInstance();
    ServletContext sc = (ServletContext) fc.getExternalContext().getContext();
    String caminhoReal = sc.getRealPath("/");
    String extensao = "";
    UploadItem item = evento.getUploadItem();
    String fileName = item.getFileName();
    String ext[] = fileName.split("\\.");
    int i = ext.length;

    if (i > 1) {
      extensao = ext[i - 1];
    }

    Long tempo = System.currentTimeMillis();
    OutputStream out =
        new FileOutputStream(caminhoReal + "/ImagensPizza/" + "img" + tempo + "." + extensao);
    setImagePath("/ImagensPizza/" + "img" + tempo + "." + extensao);

    try {
      out.write(item.getData());
      out.close();

    } catch (Exception e) {
      e.printStackTrace();
    }
  }