I'm using springmvc
, hibernate
and mysql
. Whenever I upload a file in my project the database doesn't save in HTML format, I want that user who uploads the file, the database should maintain the format. What should I do?
Uploading a method which controller calls during upload. Apart from code, any general idea would be appreciated.
private String getContentDescription(MultipartFile file, Long contentCategoryId) {
StringBuffer contentDescription = new StringBuffer();
ContentHandler textHandler = new BodyContentHandler(-1);
InputStream input = null;
try {
input = file.getInputStream();
Metadata metadata = new Metadata();
this.parser.parse(input, textHandler, metadata, new ParseContext());
input.close();
} catch (IOException | SAXException | TikaException e) {
LOGGER.debug("Unable to read uploaded document", e);
}
String returnString = "";
if (null != textHandler) {
if (contentCategoryId==3 && contentCategoryId==4) {
String contentText = textHandler.toString();
returnString = contentText.substring(0, Math.max(0, contentText.length()));
} else {
String contentText = textHandler.toString();
returnString = contentText.substring(0, Math.min(1200, contentText.length()));
}
}
return returnString;
}