file resource handling &
image resizing in play!
(scala)
by david pichsenmeister
play-res & play-scalr
for play! framework 2
developed by @LeonRadley
play-res
like amazon s3 bucket
computes sha1 hash of file and uses it as
pathname
dependencies
val appDependencies = Seq(
"se.digiplant" %% "play-res" % "1.0"
)

val main = play.Project(appName, appVersio...
conf/application.conf
# Resource plugin save directory
# is relative to app, but can be absolute to filesystem also
res.de...
upload
def upload = SecuredAction(true) { implicit request =>
val file = for {
body <- request.body.asMultipartFormData
up...
reverse routing
<img src="@res.routes.ResAssets.at
("5564ac5e3968e77b4022f55a23d36630bdeb0274.jpg")" alt="" />
<img src="@...
play-scalr
image resizing “on-the-fly”
http://sharedspaces.at/{{width}}/{{height}}/
{{mode}}/file.jpg

different modes:
●
...
dependencies
val appDependencies = Seq(
"se.digiplant" %% "play-scalr" % "1.0.1"
)

conf/application.conf
# define cache, ...
reverse routing
<img src="@scalr.routes.ScalrResAssets.at
("5564ac5e3968e77b4022f55a23d36630bdeb0274.jpg", 150, 100,
"crop...
resources
http://leon.radley.se/project/
https://github.com/digiPlant/play-res
https://github.com/digiPlant/play-scalr
thanks!
feel free to add me on:

.../3x14159265
Upcoming SlideShare
Loading in...5
×

play! scala file resource handling and image resizing

3,695

Published on

file resource and image resize plugin for play! 2 framework in scala. storing files like amazon s3 bucket and resize images on the fly.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,695
On Slideshare
0
From Embeds
0
Number of Embeds
18
Actions
Shares
0
Downloads
6
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

play! scala file resource handling and image resizing

  1. 1. file resource handling & image resizing in play! (scala) by david pichsenmeister
  2. 2. play-res & play-scalr for play! framework 2 developed by @LeonRadley
  3. 3. play-res like amazon s3 bucket computes sha1 hash of file and uses it as pathname
  4. 4. dependencies val appDependencies = Seq( "se.digiplant" %% "play-res" % "1.0" ) val main = play.Project(appName, appVersion, appDependencies).settings( // to simplify the reverse routing templatesImport ++= Seq("se.digiplant._") )
  5. 5. conf/application.conf # Resource plugin save directory # is relative to app, but can be absolute to filesystem also res.default=res res.images=res/images conf/routes GET /res/:file se.digiplant.res.ResAssets.at(file) GET /images/:file se.digiplant.res.ResAssets.at(file,“images”)
  6. 6. upload def upload = SecuredAction(true) { implicit request => val file = for { body <- request.body.asMultipartFormData uploaded <- body.file("file") } yield uploaded file match { case Some(f) => { val id: String = Res.put(f.ref.file) Ok(Json.obj("url" -> id)) } case _ => BadRequest } }
  7. 7. reverse routing <img src="@res.routes.ResAssets.at ("5564ac5e3968e77b4022f55a23d36630bdeb0274.jpg")" alt="" /> <img src="@res.routes.ResAssets.at ("5564ac5e3968e77b4022f55a23d36630bdeb0274.jpg", "images")" alt="" /> direct http://www.sharedspaces. at/res/cf342662c630a41f0dcf19314a35f82e5abbc9c4.jpg
  8. 8. play-scalr image resizing “on-the-fly” http://sharedspaces.at/{{width}}/{{height}}/ {{mode}}/file.jpg different modes: ● ● ● ● ● automatic fit_exact fit_to_width fit_to_height crop
  9. 9. dependencies val appDependencies = Seq( "se.digiplant" %% "play-scalr" % "1.0.1" ) conf/application.conf # define cache, so they only need to be resized once res.scalrcache=res/scalr # Tell scalr to use scalrcache source we just created scalr.cache=scalrcache conf/routes GET /res/:width/:height/:mode/:file se.digiplant. scalr.ScalrResAssets.at(width: Int, height: Int, mode: String, file)
  10. 10. reverse routing <img src="@scalr.routes.ScalrResAssets.at ("5564ac5e3968e77b4022f55a23d36630bdeb0274.jpg", 150, 100, "crop")" alt="" /> direct http://www.sharedspaces. at/res/150/100/crop/cf342662c630a41f0dcf19314a35f82e5abbc9c 4.jpg
  11. 11. resources http://leon.radley.se/project/ https://github.com/digiPlant/play-res https://github.com/digiPlant/play-scalr
  12. 12. thanks! feel free to add me on: .../3x14159265
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×