Java File Upload

Ho to modify this java method to save a picture to /public/images/postPictures and a path to the database to retrieve image?

public Result savePost(){
Form<Post> postForm = formFactory.form(Post.class).bindFromRequest();
if(postForm.hasErrors()){
flash(“danger”,“Please correct the Post form”);
return badRequest(createPost.render(postForm));
}
Post post = postForm.get();

Http.MultipartFormData<File> body = request().body().asMultipartFormData();
Http.MultipartFormData.FilePart part = body.getFile(“picture”);

if (part!= null){
String fileName = part.getFilename();
String contentType = part.getContentType();
File file = (File) part.getFile();
} else {
flash(“error”, “Missing file”);
}
post.save();
flash(“success”,“Post save Successfully”);
return redirect(routes.PostsController.search());
}

Thank You

Play serves up files from any public folder on the classpath so you’ll need to move the files there and then store the path in the database.