play-res


License

License

Categories

Categories

Ant Build Tools
GroupId

GroupId

se.digiplant
ArtifactId

ArtifactId

play-res_2.10
Last Version

Last Version

1.1.1
Release Date

Release Date

Type

Type

jar
Description

Description

play-res
play-res
Project URL

Project URL

https://github.com/digiplant/play-res
Project Organization

Project Organization

se.digiplant

Download play-res_2.10

How to add to project

<!-- https://jarcasting.com/artifacts/se.digiplant/play-res_2.10/ -->
<dependency>
    <groupId>se.digiplant</groupId>
    <artifactId>play-res_2.10</artifactId>
    <version>1.1.1</version>
</dependency>
// https://jarcasting.com/artifacts/se.digiplant/play-res_2.10/
implementation 'se.digiplant:play-res_2.10:1.1.1'
// https://jarcasting.com/artifacts/se.digiplant/play-res_2.10/
implementation ("se.digiplant:play-res_2.10:1.1.1")
'se.digiplant:play-res_2.10:jar:1.1.1'
<dependency org="se.digiplant" name="play-res_2.10" rev="1.1.1">
  <artifact name="play-res_2.10" type="jar" />
</dependency>
@Grapes(
@Grab(group='se.digiplant', module='play-res_2.10', version='1.1.1')
)
libraryDependencies += "se.digiplant" % "play-res_2.10" % "1.1.1"
[se.digiplant/play-res_2.10 "1.1.1"]

Dependencies

compile (4)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.10.4
com.typesafe.play : twirl-api_2.10 jar 1.0.2
commons-io : commons-io jar 2.4
commons-codec : commons-codec jar 1.6

provided (1)

Group / Artifact Type Version
com.typesafe.play : play_2.10 jar 2.3.4

test (1)

Group / Artifact Type Version
com.typesafe.play : play-test_2.10 jar 2.3.4

Project Modules

There are no modules declared in this project.

Resource plugin for Play Framework 2

use it like an amazon s3 bucket. It will only store one version of a file since it computes the sha1 hash of the file and uses that as a pathname.

Add plugin to dependencies

// in you're build.sbt file

val appDependencies = Seq(
	"se.digiplant" %% "play-res" % "1.2.0"
)

// To simplify the reverse routing we can import the digiPlant namespace
TwirlKeys.templateImports += "se.digiplant._"

Add to conf/application.conf

# Resource plugin save directory
# is relative to app, but can be absolute to filesystem also
res.default=res/default

Add to conf/routes

GET    /res/:file      @se.digiplant.res.ResAssets.at(file)

# If you wan't to separate your resources into separate sources, you can add multiple routes

GET    /images/:file      @se.digiplant.res.ResAssets.at(file, "images")

Usage

Reverse routing

The play-res plugin generates a unique sha1 hash of the file and stores the file on disk in an optimal 4char/4char/sha1hash.ext directory structure. By only having to save the fileuid (5564ac5e3968e77b4022f55a23d36630bdeb0274.jpg) to the db it's easy to retrieve the image or other document.

Here are a few examples on how to get files

<img src="@res.routes.ResAssets.at("5564ac5e3968e77b4022f55a23d36630bdeb0274.jpg")" alt="" />

Or if you wan't to get the route to an file stored in a different source

<img src="@res.routes.ResAssets.at("5564ac5e3968e77b4022f55a23d36630bdeb0274.jpg", "images")" alt="" />

Advanced Usage

You can specify multiple sources if you would like to split you resources into categories, such as profile images / uploads. By then adding another source in conf/application.conf

res.profile=res/profile

you will also have to add another route

GET    /profile/:file      @se.digiplant.res.ResAssets.at(file, "profile")

Build

To build run

play

Publish

sbt publishSigned
sbt sonatypeRelease
se.digiplant

digiPlant

Versions

Version
1.1.1
1.1.0
1.0.1
1.0