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

Utilizing MongoDB and GridFS

For this recipe, we will explore how to store and deliver files with Play applications by using MongoDB and GridFS. We will continue by adding to the previous recipe. As with the previous recipe, this recipe will be Scala only.

How to do it…

Let's take the following steps:

  1. Run the foo_scala application with Hot-Reloading enabled:
        activator "~run"
    
  2. Modify foo_scala/app/controllers/WarehouseController.scala by adding the following content:
     import java.text.SimpleDateFormat import play.api.libs.iteratee.Enumerator def upload = Action(parse.multipartFormData) { request => request.body.file("asset") match { case Some(asset) => { val gridFs = Warehouse.assets val uploadedAsset = gridFs.createFile(asset.ref.file) uploadedAsset.filename ...

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