O'Reilly logo

Play Framework Cookbook - Second Edition by Giancarlo Inductivo, Alexander Reelsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Uploading files

For this recipe, we will learn how to upload files in Play applications. The ability to upload files is one of the more important aspects of web applications, and we will see here how Play makes file uploads straightforward and easy to handle.

How to do it…

For Java, we need to take the following steps:

  1. Run the foo_java application with Hot-Reloading enabled.
  2. Add a new view template in foo_java/app/views/form.scala.html for the file upload form with the following contents:
    @helper.form(action = routes.Application.handleUpload, 'enctype -> "multipart/form-data") {
        Profile Photo: <input type="file" name="profile">
        
        <div>
            <input type="submit">
        </div>
        
    }
  3. Modify foo_java/app/controllers/Application.java by adding the following actions:
     import ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required