code: @PreAuthorize("isAuthenticated()")
      public E uploadFile(MultipartFile file) throws Exception {
  
          if (file == null) {
              final String errMsg = "Upload failed. File is null.";
              LOG.error(errMsg);
              throw new Exception(errMsg);
          } else if (file.isEmpty()) {
              final String errMsg = "Upload failed. File is empty.";
              LOG.error(errMsg);
              throw new Exception(errMsg);
          }
  
          InputStream is = null;
          byte[] fileByteArray = null;
          E fileToPersist = getEntityClass().newInstance();
  
          try {
              is = file.getInputStream();
              fileByteArray = IOUtils.toByteArray(is);
          } catch (Exception e) {
              throw new Exception("Could not create the bytearray: " + e.getMessage());
          } finally {
              IOUtils.closeQuietly(is);
          }
  
          fileToPersist.setFile(fileByteArray);
          fileToPersist.setFileType(file.getContentType());
          fileToPersist.setFileName(file.getOriginalFilename());
  
          dao.saveOrUpdate(fileToPersist);
  
          return fileToPersist;
      }
docs: Method persists a given MultipartFile as a bytearray in the database
  
  @param file
  @throws Exception