How can I solve this problem?


(Mahadi) #1

Though in dev mode it is possible to upload files by ref.move to() method in public folder in play framework and rendering that file by AssetsFinder 's path() method. But in prod mode uploading file in public 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("/uploads/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)">

enter image description here

enter image description here


(Mahadi) #2

this is the solve:

https://www.playframework.com/documentation/2.6.x/JavaStream#Standard-responses-and-Content-Length-header