Though in dev mode it is possible to upload files by ref.move to() method in public folder or any app folder in play framework and rendering that file by AssetsFinder 's path() method. But in prod mode uploading file in public folder or app folder is not allowed. In this case what I can do to access the app outer folder files and what will be the actual rendering method to render the file (images) in template? Looking for a detail solution…
package controllers
import javax.inject.{Inject, Singleton}
import play.api.mvc.{AbstractController, Action, AnyContent, ControllerComponents}
@Singleton
class ImageServerController @Inject()(cc: ControllerComponents)
extends AbstractController(cc) {
def serveImages(imageName:String): Action[AnyContent] = Assets.versioned("/tmp/images",imageName)
}
config file
GET /test controllers.TestController.test
GET /dynamicassets/*file controllers.ImageServerController.serveImages(file)
accessing views
package controllers
import javax.inject.{Inject, Singleton}
import play.api.mvc.{AbstractController, Action, AnyContent, ControllerComponents}
@Singleton
class TestController @Inject()(cc: ControllerComponents)(implicit assetsFinder: AssetsFinder)
extends AbstractController(cc) {
def test:Action[AnyContent]=Action{
Ok(views.html.testview("hotelapp.jpeg"))
}
}
here view
@(fileName:String)
<img src="@routes.ImageServerController.serveImages(fileName)">