[Plat-2.1-Java] Get image from database (image stored in database) and render in view

504 views
Skip to first unread message

Mohit Garg

unread,
Mar 7, 2013, 9:30:25 AM3/7/13
to play-fr...@googlegroups.com
Hello all,

I am new to play framework.

I want to render image on my view page. This image is stored on cloud like Amazon s3.

 
Can you guys give me an idea or some sample code for this problem.??

Thanks in advance friends...

 

Alban Dericbourg

unread,
Mar 8, 2013, 4:09:24 AM3/8/13
to play-fr...@googlegroups.com
Hi,

I guess you retrieve your image as a byte array from the database. Then you can serve it directly from the controller.
To give you a minimal example:

Controller:
public static Result renderLogo() {
   
byte[] image = YourService.getLogo();
   
return ok(image).as("image/jpeg");
}

Route:
GET   /image/logo   controllers.Image.renderLogo()

Template:
<img src="@routes.Image.renderLogo()" alt="This is my logo" />

I haven't tried but this should work.

André Filipe

unread,
Jul 16, 2013, 3:11:44 PM7/16/13
to play-fr...@googlegroups.com
Did you get success?

Alban Dericbourg

unread,
Jul 17, 2013, 7:00:02 AM7/17/13
to play-fr...@googlegroups.com
Hi,


I just tried and yes, it works.
Here is a sample to upload your images and then display them using what I described a few months ago : <https://github.com/adericbourg/play2-image-sample>.

Regards,

Alban


--
You received this message because you are subscribed to a topic in the Google Groups "play-framework" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/play-framework/9JQCSWP2_Ss/unsubscribe.
To unsubscribe from this group and all its topics, send an email to play-framewor...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages