Пример #1
0
  @Security.Authenticated(Secured.class)
  public static Result upload() {
    User user = getCurrentUser();
    if (!user.isAdmin) return redirect(routes.Application.contacts());
    Http.MultipartFormData body = request().body().asMultipartFormData();
    Http.MultipartFormData.FilePart contactfile = body.getFile("contactfile");
    if (contactfile != null) {
      String fileName = contactfile.getFilename();
      File file = contactfile.getFile();

      try {
        File f = new File("public/upload/" + fileName);
        if (f.isFile()) f.delete();
        FileUtils.moveFile(file, new File("public/upload", fileName));
      } catch (IOException ioe) {
        System.out.println("Problem operating on filesystem");
      }

      PoiExcelFileReader.readFile(fileName);
      flash("success", "Datei: " + fileName + " hochgeladen und Kontakte importiert");
      return redirect(routes.Application.contacts());
    } else {
      flash("error", "Ein Fehler ist aufgetreten, bitte versuchen sie es erneut");
      return redirect(routes.Application.contacts());
    }
  }
Пример #2
0
 @Security.Authenticated(Secured.class)
 public static Result download() {
   User user = getCurrentUser();
   if (!user.isAdmin) return redirect(routes.Application.contacts());
   String filename = PoiExcelFileReader.writeFile(Contact.all());
   response().setContentType("application/x-download");
   String headerName = "Content-disposition";
   String headerValue = "attachment; filename=" + filename;
   response().setHeader(headerName, headerValue);
   return ok(new File(filename));
   // return redirect(routes.Application.contacts());
 }