Skip to content

Instantly share code, notes, and snippets.

@letnotimitateothers
Forked from steren/Application.java
Last active September 13, 2015 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save letnotimitateothers/920cac40b1f2fcdfabc5 to your computer and use it in GitHub Desktop.
Save letnotimitateothers/920cac40b1f2fcdfabc5 to your computer and use it in GitHub Desktop.
Upload and store image with Play! Framework
public class Application extends Controller {
public static void index() {
render();
}
public static void uploadPicture(Picture picture) {
picture.save();
index();
}
public static void getPicture(long id) {
Picture picture = Picture.findById(id);
response.setContentTypeIfNotSet(picture.image.type());
renderBinary(picture.image.get());
}
}
<ul>
#{list items:models.Picture.findAll(), as:'picture'}
<li>${picture.id} <img src="@{Application.getPicture(picture.id)}" /></li>
#{/list}
</ul>
#{form @Application.uploadPicture(), enctype:'multipart/form-data'}
<input type="file" name="picture.image" />
<input type="submit" name="submit" value="Save" />
#{/form}
@Entity
public class Picture extends Model {
public Blob image;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment