use of alien4cloud.utils.ImageQuality in project alien4cloud by alien4cloud.
the class ImageServlet method doGet.
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
final String imageId = req.getParameter("id");
final String quality = req.getParameter("quality");
final ImageQuality imageQuality;
if (quality == null) {
imageQuality = ImageQuality.QUALITY_BEST;
} else {
imageQuality = ImageQuality.valueOf(quality);
}
final ImageData imageData = this.imageDAO.readImage(imageId, imageQuality);
if (imageData != null) {
// Set content type
resp.setContentType(imageData.getMime());
// Set content size
resp.setContentLength(imageData.getData().length);
// Open the file and output streams
final OutputStream out = resp.getOutputStream();
try {
out.write(imageData.getData());
} finally {
out.close();
}
} else {
resp.setStatus(HttpStatus.NOT_FOUND.value());
}
}
Aggregations