Reputation:
Is there any way to the path of image in the database and display it on view page and how to display image in view page using playframework2.0
Upvotes: 3
Views: 1348
Reputation: 14649
html:
@(name:String)
<img class="myClass" alt="myAlt" src="@routes.Application.image(name)">
Controller:
object Application extends Controller {
def image(name:String) = Action {
val MimeType = "image/png"
try {
val imageData: Array[Byte] = fetchImageFromDatabase(name)
Ok(imageData).as(MimeType)
}
catch {
case e: IllegalArgumentException =>
BadRequest("Couldn’t generate image. Error: " + e.getMessage)
}
}
def fetchImageFromDatabase(name: String): Array[Byte] = {
//import java.io.ByteArrayOutputStream
//import java.awt.image.BufferedImage
......
}
}
routes:
GET /images/:name controllers.Application.image(name: String)
Upvotes: 3