0
public static void getImage(String fileName) {
        File file = new File( "~/" + fileName );
        response.contentType = "image/png";
        renderBinary( file );
    }

In this method response and renderBinary are showing errors

arjun d n
  • 35
  • 1
  • 9

2 Answers2

1

The code that you are using is for Playframework 1.x, and it is not compatible with the 2.x version. These two versions are totally different.

As @rags mentioned, take a look at How to render a binary with play 2.0?

More explanations on Content-Type are available here: http://www.playframework.com/documentation/2.1.1/JavaResponse

Community
  • 1
  • 1
ndeverge
  • 21,378
  • 4
  • 56
  • 85
1

public static Result getImage() throws IOException { File file = new File( "d:\Images\"+name+".jpg" );

    return ok(org.apache.commons.io.FileUtils.readFileToByteArray(file)).as("image/jpeg");
}

Here I am using IOException because I am using file operations, this is another way used rather than renderBinary

arjun d n
  • 35
  • 1
  • 9