use of py.org.fundacionparaguaya.pspserver.common.exceptions.InternalServerErrorException in project FP-PSP-SERVER by FundacionParaguaya.
the class ImageParser method parse.
public static ImageDTO parse(String fileString, String imageDirectory) {
ImageDTO image = null;
// Image format validation (MIME type: image/jpeg, image/png, image/bmp, ...)
String data = fileString.substring(0, fileString.indexOf(';'));
String attribute = data.substring(0, data.indexOf(':'));
if ("data".equals(attribute)) {
String contentType = data.substring(data.indexOf(':') + 1);
String type = contentType.substring(0, contentType.indexOf('/'));
if ("image".equals(type)) {
String format = contentType.substring(contentType.indexOf('/') + 1);
String base64 = fileString.substring(fileString.indexOf(',') + 1);
Base64.Decoder decoder = Base64.getDecoder();
byte[] fileBytes = decoder.decode(base64);
File file;
try {
file = File.createTempFile("file", ".tmp");
Files.write(fileBytes, file);
} catch (IOException e) {
LOG.error(e.getMessage(), e);
throw new InternalServerErrorException(e);
}
image = new ImageDTO();
image.setFile(file);
image.setFormat(format);
image.setImageDirectory(imageDirectory);
}
}
return image;
}
use of py.org.fundacionparaguaya.pspserver.common.exceptions.InternalServerErrorException in project FP-PSP-SERVER by FundacionParaguaya.
the class TermCondPolServiceImpl method saveTerms.
@Override
public TermCondPolDTO saveTerms(MultipartFile htmlFile, TermCondPolDTO termCondPolDTO) {
try {
String htmlContent = new String(htmlFile.getBytes(), "UTF-8");
TermCondPolEntity entity = mapper.dtoToEntity(termCondPolDTO);
entity.setHtml(htmlContent);
return mapper.entityToDto(repository.save(entity));
} catch (IOException e) {
throw new InternalServerErrorException(e);
}
}
Aggregations