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();
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”);
flash(“success”,“Post save Successfully”);
return redirect(;

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.