4

In my application I need to serve a static file from public folder. And for some reasons I have to do it from Java controller action.

The first solution that came to my mind is to do something like:

public class Central extends Controller {
     public static Result index() {
         return Assets.at("/public", "central/index.html", false);
     }
}

But Assets.at method return type is play.api.mvc.Action<play.api.mvc.AnyContent>

Is there some way to transform it to type play.mvc.Result ?

Or any other elegant way to do serve static file from Java controller action ?

malloc4k
  • 1,742
  • 3
  • 22
  • 22
  • I found this answer for you: http://stackoverflow.com/questions/8305853/how-to-render-a-binary-with-play-2-0 – fredjam Aug 27 '14 at 21:53
  • Why do you want result instead of action? Result can't be used outside action. – cchantep Aug 28 '14 at 09:31
  • I can and I guess I should return Result from my index() action. But I have no idea what use of play.api.mvc.Action can I make. – malloc4k Aug 28 '14 at 10:01

1 Answers1

4

change your method return type. like this:

public class Central extends Controller {
     public static play.api.mvc.Action<play.api.mvc.AnyContent> index() {
         return Assets.at("/public", "central/index.html", false);
     }
}
Nik Kashi
  • 4,447
  • 3
  • 40
  • 63