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/.
For Java, we need to take the following steps:
Run the
foo_java
application with Hot-Reloading enabled:activator "~run"
Declare play-s3 as a project dependency in
build.sbt
:"com.amazonaws" % "aws-java-sdk" % "1.3.11"
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"
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()); } ...