Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Upload and store image with Play! Framework
public class Application extends Controller {
public static void index() {
public static void uploadPicture(Picture picture) {;
public static void getPicture(long id) {
Picture picture = Picture.findById(id);
#{list items:models.Picture.findAll(), as:'picture'}
<li>${} <img src="@{Application.getPicture(}" /></li>
#{form @Application.uploadPicture(), enctype:'multipart/form-data'}
<input type="file" name="picture.image" />
<input type="submit" name="submit" value="Save" />
public class Picture extends Model {
public Blob image;

This comment has been minimized.

Copy link

stewarf commented Mar 18, 2013

Also you can use the routes file to create friendly urls in the image links:


GET /images/blobstored/{id}.jpg Application.getPicture


<img src="/images/blobstored/${}.jpg" />

This comment has been minimized.

Copy link

arsenanai commented Apr 1, 2013

Hello, how to do the same in current version of play framework for java 2.1.1?
I didn't understand how to write " renderBinary(picture.image.get()); " in play 2?


This comment has been minimized.

Copy link

frankhn commented Aug 16, 2018

got it, what if i want to save the image to a folder and path to the database
please guide me , am using play 2.6; and how would i retrieve the image then? thanks in advance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.