0

I am trying to render image thru BufferedArray using Play Framework. The images are not being rendered with any of the following approaches. Any pointers are really helpful

  1. Returned byte[] from Bean and rendered in main.scala using @bean.property. I can see the data coming by viewing source.
  2. Wrote the image to temporary location and using the URL returned in " > tag. No success.
  3. Used inline image approach (http://en.wikipedia.org/wiki/Data_URI_scheme) (with and without Base64 encoding and image file size less than 32KB) but still no luck.

Any help/pointers are really appreciated.

Ashish
  • 421
  • 9
  • 22

1 Answers1

0

I am using Play!Framework 2.1.0. Let, the image is located at D:\\Images\\juventus.jpg (I am Windows user). Below is the solution for your problem :

public static Result showImage() {
    try {
        byte[] array = Files.toByteArray(new File("D:\\Images\\juventus.jpg"));
        return ok(array); // render image
    } catch (IOException e) {
        Logger.error("An IO Exception is occured while reading file!");
    }
    return internalServerError("An IO Exception is occured while reading file!");
}

That should render the image as a response. May this post is useful.. ;)

Wayan Wiprayoga
  • 4,472
  • 4
  • 20
  • 30