Amazon S3 module for Play Framework 2
resolvers += "jitpack" at "https://jitpack.io"
libraryDependencies += "com.github.0xbaadf00d" % "play-s3-module" % "release~YY.MM"
# Play Modules
# ~~~~~
play.modules.enabled += "com.zero_x_baadf00d.play.module.aws.s3.AmazonS3ModuleBinder"
# Amazon S3 Plugin
# ~~~~~
aws.s3.endpoint = "s3-eu-west-1.amazonaws.com"
aws.s3.pathstyle = false
aws.s3.bucket = "your-bucket"
aws.s3.puburl = "https://s3-eu-west-1.amazonaws.com/"
aws.access.key = "your-access-key"
aws.secret.key = "your-secret-key"
# Ebean
# ~~~~~
ebean.default = [ "models.*", "com.zero_x_baadf00d.play.module.aws.s3.ebean.S3FileModel" ]
public class MyController extends Controller {
private final AmazonS3Module amazonS3;
@Inject
public MyController(final AmazonS3Module amazonS3) {
this.amazonS3 = amazonS3;
}
public Result index() {
// Do something with this.amazonS3.getService()
return ok();
}
}
final AmazonS3Module amazonS3 = Play.application().injector().instanceOf(AmazonS3Module.class);
// Do something with amazonS3.getService()
public class MyController extends Controller {
public Result index() {
final File avatar = new File("/tmp/avatar.png");
final S3FileModel s3avatar = new S3FileModel();
s3avatar.setName("avatar.png");
s3avatar.setSubDirectory("account-avatar");
s3avatar.setObject(avatar);
s3avatar.setContentType("image/png");
s3avatar.save();
return ok(s3avatar.getUrlAsString());
}
}
This project is released under terms of the MIT license.