use of org.openforis.collect.model.LogoPosition in project collect by openforis.
the class LogoController method downloadLogo.
@RequestMapping(value = "/downloadLogo.htm", method = RequestMethod.GET)
@ResponseBody
public void downloadLogo(HttpServletRequest request, HttpServletResponse response, @RequestParam String position) {
LogoPosition p = LogoPosition.valueOf(position.toUpperCase());
Logo logo = logoManager.loadLogo(p);
if (logo != null) {
byte[] data = logo.getImage();
ByteArrayInputStream is = new ByteArrayInputStream(data);
try {
String contentType = logo.getContentType();
if (contentType == null) {
contentType = "image/jpg";
}
// TODO get extension from db
String extension = "jpg";
Controllers.writeFileToResponse(response, is, "logo." + extension, contentType, data.length);
} catch (IOException e) {
log.error("Error writing logo in position: " + position, e);
}
}
}
use of org.openforis.collect.model.LogoPosition in project collect by openforis.
the class LogoController method uploadLogo.
@RequestMapping(value = "/uploadLogo.htm", method = RequestMethod.POST)
@ResponseBody
public String uploadLogo(UploadItem uploadItem, BindingResult result, @RequestParam String position) throws IOException, SurveyImportException, IdmlParseException {
CommonsMultipartFile fileData = uploadItem.getFileData();
InputStream is = fileData.getInputStream();
ByteArrayOutputStream output = new ByteArrayOutputStream();
IOUtils.copy(is, output);
byte[] byteArray = output.toByteArray();
String contentType = fileData.getContentType();
LogoPosition p = LogoPosition.valueOf(position.toUpperCase());
Logo logo = new Logo(p, byteArray, contentType);
logoManager.save(logo);
return "ok";
}
Aggregations