Here's my code:
1.Java Code:
public static void getImg(Long itemId) {
try {
Item item = Item.findById(itemId);
if (item.img != null && item.img.getFile() != null{
response.setContentTypeIfNotSet(item.img.type());
renderBinary(item.img.get());
}
} catch (Exception e) {
Logger.error("Can't find image,itemId = " + itemId);
}
}
html : < img src="@{{ Items.getImage(123)}}"/>
2.
html : < img src="/public/images/123.jpg"/>
I'm using playframework and the samples from documentation display images via the first version. What's the different (deep into mechanism) between them, especially in response performance ?
In the 1st version, since you get the actual filename from some business logic (and/or database), you can easily rename/replace the image of id '123' without needing to change the presentation tiers.
ReplyDeleteIf the image of id '123' is in a protected folder (HTTP Basic Authentication or similar), your business logic could make sure the access is granted through an application wide security mechanism.
You could also have versioning of the image, by providing the path of the desired version according to other Request/Session parameter and logic.
In the 2nd case, it is possible to perform the above scenario but much more costly in development time and possibly configuration.