Book Image

Play Framework Cookbook - Second Edition

By : Alexander Reelsen, Giancarlo Inductivo
Book Image

Play Framework Cookbook - Second Edition

By: Alexander Reelsen, Giancarlo Inductivo

Overview of this book

<p>As web and mobile systems become more sophisticated, anchoring systems in a mature, solid framework has become increasingly important. Play 2 provides developers with the necessary tools to build robust web applications.</p> <p>This book is a compilation of useful recipes aimed at helping developers discover the power of Play 2. The introductory section serves as a primer to Play Framework, wherein all the fundamentals of the framework are covered extensively. It then explains the usage of controllers and how modules can be leveraged for optimal performance. Next, the book walks you through creating and using APIs, followed by extensive real-world applications. Finally, you will learn to manage applications post production.</p>
Table of Contents (15 chapters)
Play Framework Cookbook Second Edition
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Integrating Play application with Amazon S3


For this recipe, we will explore how Play applications can upload files directly to Amazon Web Services (AWS) S3, a popular cloud storage solution.

For more information about S3, please refer to http://aws.amazon.com/s3/.

How to do it…

For Java, we need to take the following steps:

  1. Run the foo_java application with Hot-Reloading enabled:

        activator "~run"
    
  2. Declare play-s3 as a project dependency in build.sbt:

        "com.amazonaws" % "aws-java-sdk" % "1.3.11"
  3. Specify your AWS credentials in foo_java/conf/application.conf:

        aws.accessKeyId="YOUR S3 ACCESS KEY"
        aws.secretKey="YOUR S3 SECRET KEY"
    
        fooscala.s3.bucketName="YOUR S3 BUCKET NAME"
  4. Modify foo_java/app/controllers/Application.java by adding the following code:

           import com.amazonaws.auth.*;
           import com.amazonaws.services.s3.*;
           import com.amazonaws.services.s3.model.*;
    
           public static Result s3Upload() {
             return ok(views.html.s3.render());
           }
    
         ...