/** * Helper method creates a temp file from the multipart form data and persists the upload file * metadata to the database * * @param filePart data from the form submission * @return an instance of UploadFile that has been persisted to the db */ private static UserUpload uploadFile(Http.MultipartFormData.FilePart filePart) { File src = (File) filePart.getFile(); File file = null; try { file = File.createTempFile(filePart.getFilename() + "-", ".csv"); FileUtils.copyFile(src, file); } catch (IOException e) { throw new RuntimeException("Could not create temp file for upload", e); } UserUpload uploadFile = new UserUpload(); uploadFile.absolutePath = file.getAbsolutePath(); uploadFile.fileName = filePart.getFilename(); uploadFile.user = Application.getCurrentUser(); uploadFile.save(); return uploadFile; }
@Security.Authenticated(Secured.class) public Result deploy() { Http.MultipartFormData body = request().body().asMultipartFormData(); Http.MultipartFormData.FilePart filePart = body.getFile("filename"); if (filePart != null) { ConfigManager configManager = ConfigManager.getInstance(); try { configManager.unpack((File) filePart.getFile()); } catch (Exception e) { flash("error", "Could not verify package."); return redirect(routes.Workflows.uploadWorkflow()); } flash("message", "Packages zip file was successfully deployed"); return redirect(routes.Workflows.uploadWorkflow()); } else { flash("error", "Missing file"); return badRequest(); } }